Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Added timestamp utils to mip sdk #108

Open
wants to merge 186 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
215d3b7
Moved timestamp utils into mip sdk
rafarrel Jun 4, 2024
c649777
Changed timestamp utils to be in mip namespace
rafarrel Jun 4, 2024
1447e95
Updated OS check for timestamp synchronize() to check for C++ 20
rafarrel Jun 4, 2024
fdf13cb
Added C++ 20 check for chrono time units
rafarrel Jun 4, 2024
a395990
Added manual chrono duration aliases for C++ < 20
rafarrel Jun 4, 2024
851add5
Merge branch 'develop' into feature/timestamp_utils
rafarrel Jun 4, 2024
8d9c871
Hopefull comment fix in Jenkins?
rafarrel Jun 4, 2024
443cc57
Included cassert
rafarrel Jun 4, 2024
9e76eb6
Switched include to assert.h
rafarrel Jun 4, 2024
e709c09
Removed Months from timestamp utils
rafarrel Jun 20, 2024
c3ffef2
Changed private member variable name
rafarrel Jun 20, 2024
ca90ef3
Removed symmetric example
rafarrel Jun 20, 2024
6d14e38
Removed trailing space
rafarrel Jun 20, 2024
76f2279
Moved timestamp functions back into class and renamed class to Timest…
rafarrel Jun 20, 2024
fac0aac
Renamed file to timestamp_manager
rafarrel Jun 20, 2024
d155d7c
Added blank test for timestamp manager and commented out failing/stal…
rafarrel Jun 20, 2024
c5227e5
Added failing tests back
rafarrel Jun 21, 2024
2a369f5
Added test case skeletons for getTimestamp
rafarrel Jun 21, 2024
ffc73c1
Added test for getTimestamp (template base)
rafarrel Jun 21, 2024
81a4b3b
Refactored getTimestamp test
rafarrel Jun 21, 2024
83bd4d3
Implemented test for getTimestamp template function (currently failing)
rafarrel Jun 21, 2024
c656353
Added failure output for base function getTimestamp tests
rafarrel Jun 21, 2024
777addf
Added generalized testCase function for timestamp type tests
rafarrel Jun 21, 2024
0fdf0f2
Revampled testCase functions
rafarrel Jun 21, 2024
3a7404b
Refactored test with new testCase function interface
rafarrel Jun 21, 2024
caa80a8
Fixed faulty test for GetTimestamp-value
rafarrel Jun 21, 2024
e28fd31
Organized utility functions
rafarrel Jun 21, 2024
9a2de21
Refactored getTimeOfWeek method and add test skeleton
rafarrel Jun 21, 2024
f3dafe2
Minor stuff
rafarrel Jun 24, 2024
eac85cf
Refactored test time conversion stuff
rafarrel Jun 24, 2024
d65e918
Refactored getter tests into single function
rafarrel Jun 24, 2024
287d702
Removed legend from docstring
rafarrel Jun 24, 2024
828e4b8
Added base method for getTimeOfWeek (nanoseconds)
rafarrel Jun 24, 2024
1898d3e
Switched test_time for nanoseconds_in_week
rafarrel Jun 24, 2024
5688592
Added non-zero check for start_time constructor
rafarrel Jun 24, 2024
255594b
Moved tests back into separate functions
rafarrel Jun 24, 2024
3dfc56a
Added more representative test time for getTimestamp
rafarrel Jun 24, 2024
b9ac96a
Refactored getTimeOfWeek methods and added working tests
rafarrel Jun 24, 2024
54f80a2
Moved all getter tests back into single function
rafarrel Jun 24, 2024
575f0a8
Changed synchronize() to synchronizeGPS()
rafarrel Jun 24, 2024
5a7b158
Add synchronize constructor and time standard check + refactored othe…
rafarrel Jun 24, 2024
bf8e596
Updated documentation for synchronize method
rafarrel Jun 25, 2024
418279a
Added base for TimeStandard struct
rafarrel Jun 26, 2024
b8afc76
Refactored TimeStandard interface
rafarrel Jun 26, 2024
fa96bfa
Moved synchronize logic back into main method
rafarrel Jun 26, 2024
ecdcd03
Moved time_since_epoch() to cpp file
rafarrel Jun 26, 2024
235b412
Moved timeSinceEpoch and epochDifference methods into TimestampManager
rafarrel Jun 26, 2024
01fc5d2
Implemented epochDifference method
rafarrel Jun 26, 2024
62e73e0
Refactored epochDifference back into TimeStandard
rafarrel Jun 26, 2024
9f2cc16
Deleted default constructor for TimeStandard to force explicit time s…
rafarrel Jun 26, 2024
701c066
Moved epoch difference logic into synchronize()
rafarrel Jun 26, 2024
544da85
(Not building) current foundation for new direction of Timestamp afte…
rafarrel Jun 27, 2024
8e84a31
Renamed timestamp_manager file
rafarrel Jul 2, 2024
cdfef9f
Moved time standard into separate file
rafarrel Jul 2, 2024
d670f71
Switched duration units in time standard to use chrono
rafarrel Jul 2, 2024
41a6e4f
Moved time duration definitions into separate file
rafarrel Jul 2, 2024
54a8453
Added mip custom time durations (uint32 and uint64)
rafarrel Jul 2, 2024
91f7a68
Deleted default constructor for timestamp experimental
rafarrel Jul 2, 2024
ae4f6c4
Commented out timestamp stuff to rebuild from the ground up
rafarrel Jul 2, 2024
7dfe614
Fixed redefinition issue for timestamp constructor
rafarrel Jul 2, 2024
42fed40
Added (failing) test for invalid constructor
rafarrel Jul 2, 2024
d936dd5
Failing constructor test fleshed out
rafarrel Jul 2, 2024
1162c03
Fixed test failing due to unsigned integers --> changed duration unde…
rafarrel Jul 2, 2024
5e98a80
Added valid input test for manual time constructor
rafarrel Jul 3, 2024
2b21c9d
Added time standard attribute to Timestamp class and set manual time …
rafarrel Jul 3, 2024
e607ea5
Added test declarations and moved main above test definitions
rafarrel Jul 3, 2024
fa228b3
Added back test for get timestamp base
rafarrel Jul 3, 2024
6cf710e
Added getTimestamp() base method back (passing)
rafarrel Jul 3, 2024
f2d8ecc
Added back test for getTimestamp() template (failing)
rafarrel Jul 3, 2024
f16fe5f
GetTimestamp-template test passing
rafarrel Jul 3, 2024
25f943f
Added synchronize-unix test (failing)
rafarrel Jul 3, 2024
13b028f
Fixed constructor taking in a time standard as its only argument
rafarrel Jul 3, 2024
13cffba
Fixed testSynchronizeUnix test (still failing)
rafarrel Jul 3, 2024
915ee8c
Aligned outputCaseResults output
rafarrel Jul 3, 2024
5154f30
testSynchronizeUnix passing
rafarrel Jul 3, 2024
9376ce7
Removed no longer needed utilities
rafarrel Jul 3, 2024
aa1d9ef
Minor refactor
rafarrel Jul 3, 2024
4d2276e
Changed testSynchronize() to use mock time standard for reproducibility
rafarrel Jul 3, 2024
6b47b43
Minor refactor
rafarrel Jul 3, 2024
3c8b47b
Added test for Now() (failing)
rafarrel Jul 3, 2024
1c40f77
Added Now() (test passing)
rafarrel Jul 3, 2024
838f61d
Moved old comments from timestamp to time standard
rafarrel Jul 3, 2024
5a74a73
Cleaned up test structure for better readability and easier modification
rafarrel Jul 8, 2024
ac066f7
Removed no longer needed includes from test file
rafarrel Jul 8, 2024
2841419
Minor refactor of current tests
rafarrel Jul 8, 2024
7c3aec3
Updated documentation for synchronize method
rafarrel Jul 8, 2024
cb58be2
Added test for setTimestamp (failing)
rafarrel Jul 8, 2024
b2653ae
Set timestamp tests passing
rafarrel Jul 8, 2024
b6675c7
Added invalid input time check method
rafarrel Jul 8, 2024
971bd26
Added tests for invalid input times (added new test case function)
rafarrel Jul 8, 2024
a966222
Minor naming refactor for test utilities
rafarrel Jul 8, 2024
41b5738
Switched out manual constructor tests with invalidInputTestCase
rafarrel Jul 8, 2024
701c8bb
Removed excessive valid input tests for manual constructor
rafarrel Jul 8, 2024
9809912
Re-designed getTimestamp test
rafarrel Jul 8, 2024
2dcee81
Moved mock objects to top section
rafarrel Jul 8, 2024
3e07d91
Standardized test values
rafarrel Jul 8, 2024
6515eba
Added test for getTimeOfWeek [equal] (failing)
rafarrel Jul 8, 2024
e18224b
GetTimeOfWeek equal test passing
rafarrel Jul 8, 2024
72cb09b
Added passing tests for less than week and more than week
rafarrel Jul 8, 2024
1a913fd
Added tests for setTimeOfWeek (failing)
rafarrel Jul 9, 2024
45b03c0
implemented setTimeOfWeek (passing)
rafarrel Jul 9, 2024
4e9a189
Refactored setTimeOfWeek
rafarrel Jul 9, 2024
263a08c
Added tests for setWeek (failing)
rafarrel Jul 9, 2024
8c0fc13
Implemented setWeek (passing)
rafarrel Jul 9, 2024
685c97b
Refactored setWeek
rafarrel Jul 9, 2024
09219d2
Added tests for timeElapsed (failing)
rafarrel Jul 9, 2024
b266d08
Added unexpected exception checking for tests
rafarrel Jul 10, 2024
fc3401e
Implemented timeElapsed (passing)
rafarrel Jul 10, 2024
daac368
Refactored getterTestCase functions
rafarrel Jul 10, 2024
b1409dc
Began major refactor of test structure
rafarrel Jul 10, 2024
5e1961b
Refactored output failure messages
rafarrel Jul 10, 2024
858a66b
Added back getTimestamp tests
rafarrel Jul 10, 2024
7867265
Implemented new auto-run test structure
rafarrel Jul 10, 2024
00f855b
Added TestSuite class for convenience
rafarrel Jul 11, 2024
58cb65f
Set test suite runner to run tests in order of when they are added
rafarrel Jul 11, 2024
1f561ee
Added setup functions to tests
rafarrel Jul 11, 2024
0768e07
Added raw timestamp getter and setter tests back in new format
rafarrel Jul 11, 2024
88e6abf
Removed Now() and set default constructor to synchronize
rafarrel Jul 11, 2024
81e5dc8
Added back set week tests in new structure
rafarrel Jul 11, 2024
ab9cce7
Added back time of week tests in new structure
rafarrel Jul 11, 2024
d4abac4
Added test for invalid template duration for getTimeOfWeek
rafarrel Jul 11, 2024
d7af6d6
Added check for getTimeOfWeek duration template argument (passing)
rafarrel Jul 11, 2024
24b6769
Added back set time of week tests in new structure + refactored/chang…
rafarrel Jul 11, 2024
8890861
Added back timeElapsed tests
rafarrel Jul 11, 2024
be0211a
Added TimeElapsedRelativeCheck tests to set up for differentiation fr…
rafarrel Jul 11, 2024
8fd8d16
Added tests for timeChanged (failing)
rafarrel Jul 11, 2024
1044bfa
Implemented timeChanged (passing)
rafarrel Jul 11, 2024
4e95a59
Removed excessive validation methods
rafarrel Jul 12, 2024
a7105af
Added tests for castTime (failing)
rafarrel Jul 12, 2024
e36b75b
Implemented castTime (passing)
rafarrel Jul 12, 2024
9dc5c97
Fixed format call functions used in outputCaseResults()
rafarrel Jul 12, 2024
5baa484
Added tests for increment (failing)
rafarrel Jul 12, 2024
62c4c9d
Revamped tests for increment()
rafarrel Jul 12, 2024
5c26147
Added test for invalid increment input --> old reference > synced ref…
rafarrel Jul 12, 2024
50f7526
Fixed mock increment object
rafarrel Jul 12, 2024
63f1923
Implemented increment() (passing)
rafarrel Jul 12, 2024
9c417a7
Revamped increment tests to cover more edge cases
rafarrel Jul 15, 2024
5a6493a
Added tests for convert (failing)
rafarrel Jul 15, 2024
9cf59bb
Changed Timestamp to take template instead of argument for time standard
rafarrel Jul 15, 2024
50f3613
Fixed template errors and changed tests to work with new template sys…
rafarrel Jul 15, 2024
99b68fa
Removed old cpp file
rafarrel Jul 15, 2024
8ab8691
Changed timestamp back to take time standard as argument instead of t…
rafarrel Jul 16, 2024
3c6ad1f
Convert tests back to original state
rafarrel Jul 17, 2024
0676702
Fixed time standard segmentation fault in tests
rafarrel Jul 17, 2024
4b79539
Changed convert to throw logic_error instead of default to zero for n…
rafarrel Jul 18, 2024
bfe4f55
Changed convert to convertFrom for readability
rafarrel Jul 18, 2024
0ed6354
Added regression tests for getTimestampBase()
rafarrel Jul 18, 2024
d74ba99
Added tests for setTimestamp (convert version) (failing)
rafarrel Jul 18, 2024
489406d
SetTimestamp (convert version) implemented (passing)
rafarrel Jul 18, 2024
62c796c
Reorganized timestamp interface in header
rafarrel Jul 18, 2024
6ed955c
Moved all non-template definitions back into cpp file
rafarrel Jul 18, 2024
144dffd
Removed unused includes from header
rafarrel Jul 18, 2024
b036471
Changed timestamp base standard naming for better readability in inte…
rafarrel Jul 19, 2024
75c312b
Added doxygen documentation for constructors
rafarrel Jul 19, 2024
e2279f6
Added doxygen documentation for synchronize
rafarrel Jul 19, 2024
0fa1366
Polished reorganization of timestamp interface
rafarrel Jul 19, 2024
e8418bb
Re-ordered method definitions in cpp file based on new interface stru…
rafarrel Jul 19, 2024
76afe87
Re-ordered method definitions in hpp file based on interface structure
rafarrel Jul 19, 2024
5ebacb3
Added time subdirectory for utils
rafarrel Jul 19, 2024
2884bad
Moved convertFrom and castTime to misc.hpp
rafarrel Jul 19, 2024
be1314d
Restructured castTime tests for new interface (failing)
rafarrel Jul 19, 2024
b9a8a77
Re-designed tests for convert for new interface
rafarrel Jul 19, 2024
fc7e27d
Implemented new versions for convert and castTime (passing)
rafarrel Jul 19, 2024
d745734
Removed unnecessary getTimestampBaseStandard method
rafarrel Jul 19, 2024
d931c94
Hopefully fixed std::invalid_argument error in build on jenkins?
rafarrel Jul 19, 2024
0462d78
Updated main timestamp class documentation, constructor documentation…
rafarrel Jul 22, 2024
2f0b632
Updated documentation for increment and add exception throw documenta…
rafarrel Jul 22, 2024
2e7103f
Updated documentation for setWeek
rafarrel Jul 22, 2024
c030fff
Updated documentation for setTimeOfWeek
rafarrel Jul 22, 2024
651447d
Removed unnecessary examples from setWeek and setTimeOfWeek documenta…
rafarrel Jul 22, 2024
f85df67
Added exception throw docs for remaing setters
rafarrel Jul 22, 2024
4ca2e8e
Updated documentation for timeElapsed and refactored reference timest…
rafarrel Jul 22, 2024
6119da1
Updated documentation for timeChanged
rafarrel Jul 22, 2024
567cd60
Simplified convert interface and began adding documentation
rafarrel Jul 22, 2024
57bb94e
Updated documentation for castTime
rafarrel Jul 22, 2024
1c0cb56
Added test for unix time now() (passing)
rafarrel Jul 22, 2024
36315bd
Added tests for unix time convert to/from base
rafarrel Jul 22, 2024
9e05e80
Added tests for GpsTime (failing)
rafarrel Jul 22, 2024
ce3cdbe
Implemented GpsTime (passing)
rafarrel Jul 22, 2024
83432c2
Removed old comments from standards.cpp
rafarrel Jul 22, 2024
cdf45d4
Added documentation for time standard extensibility
rafarrel Jul 22, 2024
64e009c
Fixed typo
rafarrel Jul 22, 2024
67ea146
Officially changed name to Timestamp
rafarrel Jul 22, 2024
ec05cfa
Renamed to TimestampNew to fix naming conflict
rafarrel Jul 23, 2024
3ef8001
Set timeChanged to const method
rafarrel Jul 23, 2024
e28ba1b
Set getTimeOfWeek to const method
rafarrel Jul 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ int/
.vs/

src/mip/mip_version.h

# Tests
Testing/
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,23 @@ configure_file(${VERSION_IN_FILE} ${VERSION_OUT_FILE})
#

set(UTILS_DIR "${MIP_DIR}/utils")

set(UTILS_SOURCES
"${UTILS_DIR}/byte_ring.c"
"${UTILS_DIR}/byte_ring.h"
"${UTILS_DIR}/serialization.c"
"${UTILS_DIR}/serialization.h"
)

set(UTILS_SUBDIR_TIME "${UTILS_DIR}/time")
set(UTILS_TIME_SOURCES
"${UTILS_SUBDIR_TIME}/durations.hpp"
"${UTILS_SUBDIR_TIME}/misc.hpp"
"${UTILS_SUBDIR_TIME}/standards.cpp"
"${UTILS_SUBDIR_TIME}/standards.hpp"
"${UTILS_SUBDIR_TIME}/timestamp.cpp"
"${UTILS_SUBDIR_TIME}/timestamp.hpp"
)

#
# MIP Control
#
Expand Down Expand Up @@ -225,6 +234,7 @@ set(ALL_MIP_SOURCES
${MIPDEV_SOURCES}
${MIP_SOURCES}
${UTILS_SOURCES}
${UTILS_TIME_SOURCES}
${MIP_CPP_HEADERS}
${MIP_INTERFACE_SOURCES}
${MIP_EXTRA_SOURCES}
Expand Down
17 changes: 17 additions & 0 deletions src/mip/utils/time/durations.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <chrono>
#include <ratio>

namespace mip
{
using Nanoseconds = std::chrono::duration<std::int64_t, std::nano>;
using Microseconds = std::chrono::duration<std::int64_t, std::micro>;
using Milliseconds = std::chrono::duration<std::int64_t, std::milli>;
using Seconds = std::chrono::duration<std::int64_t>;
using Minutes = std::chrono::duration<std::int32_t, std::ratio<60>>;
using Hours = std::chrono::duration<std::int32_t, std::ratio<3600>>;
using Days = std::chrono::duration<std::int32_t, std::ratio<86400>>;
using Weeks = std::chrono::duration<std::int32_t, std::ratio<604800>>;
using Years = std::chrono::duration<std::int32_t, std::ratio<31556952>>;
}
53 changes: 53 additions & 0 deletions src/mip/utils/time/misc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#pragma once

#include "mip/utils/time/durations.hpp"
#include "mip/utils/time/standards.hpp"

namespace mip
{
/// Converts time duration from one time standard to another.
///
/// @throws std::logic_error If time < 0 after conversion (corresponding time duration
/// doesn't exist in the other standard).
///
template<typename DurationOut = Nanoseconds, typename DurationIn>
DurationOut convert(DurationIn time, const TimeStandard &to, const TimeStandard &from);

/// Casts a time duration to the given arithmetic type.
///
/// Uses a static_cast, so typical rounding rules will apply.
///
/// @throws std::invalid_argument If time < 0 nanoseconds.
///
template<typename T, typename DurationIn>
T castTime(const DurationIn &time);


/**************************************************************************************/
/* Definitions for template declarations above. */
/**************************************************************************************/

template<typename DurationOut, typename DurationIn>
DurationOut convert(DurationIn time, const TimeStandard &to, const TimeStandard &from)
{
Nanoseconds converted = to.convertFromBase(from.convertToBase(std::chrono::duration_cast<Nanoseconds>(time)));
if (converted < Nanoseconds(0))
{
throw std::logic_error("Converted time < 0. Add exception handling with desired response!");
}

return std::chrono::duration_cast<DurationOut>(converted);

}

template<typename T, typename DurationIn>
T castTime(const DurationIn &time)
{
if (time < mip::Nanoseconds(0))
{
throw std::invalid_argument("Time < 0.");
}

return static_cast<T>(time.count());
}
} // namespace mip
36 changes: 36 additions & 0 deletions src/mip/utils/time/standards.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "mip/utils/time/standards.hpp"

namespace mip
{
Nanoseconds UnixTime::now() const
{
return std::chrono::duration_cast<Nanoseconds>(std::chrono::system_clock::now().time_since_epoch());
}

Nanoseconds UnixTime::convertToBase(Nanoseconds time) const
{
return time;
}

Nanoseconds UnixTime::convertFromBase(Nanoseconds time) const
{
return time;
}

Nanoseconds GpsTime::now() const
{
Nanoseconds now = std::chrono::duration_cast<Nanoseconds>(std::chrono::system_clock::now().time_since_epoch());

return convertFromBase(now);
}

Nanoseconds GpsTime::convertToBase(Nanoseconds time) const
{
return time + epoch_difference;
}

Nanoseconds GpsTime::convertFromBase(Nanoseconds time) const
{
return time - epoch_difference;
}
}
41 changes: 41 additions & 0 deletions src/mip/utils/time/standards.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include "mip/utils/time/durations.hpp"

namespace mip
{
/// Extend this to create a new time standard.
struct TimeStandard
{
/// Should return the currently most up-to-date time duration in this standard.
virtual Nanoseconds now() const = 0;

/// Should convert the given time duration in this standard to the corresponding time in
/// the base standard.
virtual Nanoseconds convertToBase(Nanoseconds time) const = 0;

/// Should convert the given time duration in the base standard to the corresponding
/// time in this standard.
virtual Nanoseconds convertFromBase(Nanoseconds time) const = 0;
};

/** Common standards ****************************************************************/

struct UnixTime : TimeStandard
{
Nanoseconds now() const override;
Nanoseconds convertToBase(Nanoseconds time) const override;
Nanoseconds convertFromBase(Nanoseconds time) const override;
};

struct GpsTime : TimeStandard
{
Nanoseconds now() const override;
Nanoseconds convertToBase(Nanoseconds time) const override;
Nanoseconds convertFromBase(Nanoseconds time) const override;

private:
// Accounts for epoch gap and leap seconds.
const mip::Nanoseconds epoch_difference{Seconds(315964800 - 18)};
};
} // namespace mip
78 changes: 78 additions & 0 deletions src/mip/utils/time/timestamp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include "mip/utils/time/timestamp.hpp"

#include "mip/utils/time/misc.hpp"

namespace mip
{
TimestampNew::TimestampNew(const mip::TimeStandard &standard) :
m_standard(standard)
{
synchronize();
}

void TimestampNew::synchronize()
{
m_timestamp = m_standard.now();
}

void TimestampNew::increment(const TimestampNew &reference_new, const TimestampNew &reference_old)
{
mip::Nanoseconds m_synced = reference_new.getTimestamp();
mip::Nanoseconds m_old = reference_old.getTimestamp();
if (m_synced < m_old)
{
throw std::invalid_argument("New reference timestamp < old reference timestamp.");
}

m_timestamp += (m_synced - m_old);
}

void TimestampNew::setTimestamp(Nanoseconds time)
{
if (time < Nanoseconds(0))
{
throw std::invalid_argument("Time < 0.");
}

m_timestamp = time;
}

void TimestampNew::setTimestamp(const TimestampNew &from)
{
m_timestamp = convert(from.getTimestamp(), m_standard, from.m_standard);
}

void TimestampNew::setWeek(Weeks week)
{
if (week < Weeks(0))
{
throw std::invalid_argument("Week < 0.");
}

m_timestamp = week + getTimeOfWeek();
}

void TimestampNew::setTimeOfWeek(Nanoseconds time)
{
if (time < Nanoseconds(0))
{
throw std::invalid_argument("Time of week < 0.");
}
if (time >= Weeks(1))
{
throw std::invalid_argument("Time of week >= one week.");
}

m_timestamp = std::chrono::duration_cast<Weeks>(m_timestamp) + time;
}

Nanoseconds TimestampNew::getTimestamp() const
{
return m_timestamp;
}

Nanoseconds TimestampNew::getTimeOfWeek() const
{
return m_timestamp % Weeks(1);
}
} // namespace mip
Loading