-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from simonkimi/add_timezone
Add Time Zone and Daylight Saving Time Customization for MDF Data
- Loading branch information
Showing
42 changed files
with
1,400 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#include "mdf/itimestamp.h" | ||
|
||
namespace mdf { | ||
|
||
namespace timetype | ||
{ | ||
enum MdfTimestampType { | ||
kUtcTime, /**< Represents the UTC time. */ | ||
kLocalTime, /**< Represents the local time. */ | ||
kLocalTimeTz, /**< Represents the local time with timezone offset. */ | ||
kTimezoneTime /**< Represents the time with timezone offset. */ | ||
}; | ||
} | ||
|
||
class ITimestamp; | ||
|
||
/** | ||
* \brief Interface for MDF timestamp handling. | ||
*/ | ||
class IMdfTimestamp { | ||
public: | ||
/** | ||
* \brief Set the time in nanoseconds. | ||
* \param time The time in nanoseconds. | ||
*/ | ||
virtual void SetTime(uint64_t time) = 0; | ||
/** | ||
* \brief Set the time using an ITimestamp object. | ||
* \param timestamp An ITimestamp object representing the time. | ||
*/ | ||
virtual void SetTime(ITimestamp ×tamp) = 0; | ||
/** | ||
* \brief Get the time in nanoseconds. | ||
* \return The time in nanoseconds. | ||
*/ | ||
[[nodiscard]] virtual uint64_t GetTimeNs() const = 0; | ||
/** | ||
* \brief Get the timezone offset in minutes. | ||
* \return The timezone offset in minutes. | ||
*/ | ||
[[nodiscard]] virtual uint16_t GetTzOffsetMin() const = 0; | ||
/** | ||
* \brief Get the daylight saving time offset in minutes. | ||
* \return The daylight saving time offset in minutes. | ||
*/ | ||
[[nodiscard]] virtual uint16_t GetDstOffsetMin() const = 0; | ||
/** | ||
* \brief Get the type of MDF timestamp. | ||
* \return The MDF timestamp type. | ||
*/ | ||
[[nodiscard]] virtual timetype::MdfTimestampType GetTimeType() const = 0; | ||
}; | ||
} // namespace mdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#pragma once | ||
#include <string> | ||
|
||
namespace mdf { | ||
|
||
namespace timeunits { | ||
constexpr uint64_t kNanosecondsPerSecond = 1'000'000'000; | ||
constexpr uint64_t kNanosecondsPerMinute = 60 * kNanosecondsPerSecond; | ||
constexpr uint64_t kNanosecondsPerHour = 60 * kNanosecondsPerMinute; | ||
constexpr uint32_t kSecondsPerMinute = 60; | ||
constexpr uint32_t kSecondsPerHour = 60 * kSecondsPerMinute; | ||
} // namespace timeunits | ||
|
||
/** | ||
* \brief Interface for timestamp handling in MDF files. | ||
*/ | ||
class ITimestamp { | ||
public: | ||
/** | ||
* \brief Virtual destructor for ITimestamp. | ||
*/ | ||
virtual ~ITimestamp() = default; | ||
/** | ||
* \brief Get the time in nanoseconds. | ||
* \return Time in nanoseconds. | ||
*/ | ||
[[nodiscard]] virtual uint64_t GetTimeNs() const = 0; | ||
/** | ||
* \brief Get the timezone offset in minutes. | ||
* \return Timezone offset in minutes. | ||
*/ | ||
[[nodiscard]] virtual int16_t GetTimezoneMin() const = 0; | ||
/** | ||
* \brief Get the daylight saving time offset in minutes. | ||
* \return DST offset in minutes. | ||
*/ | ||
[[nodiscard]] virtual int16_t GetDstMin() const = 0; | ||
/** | ||
* \brief Get the UTC time in nanoseconds. | ||
* \return UTC time in nanoseconds. | ||
*/ | ||
[[nodiscard]] virtual uint64_t GetUtcTimeNs() const = 0; | ||
}; | ||
|
||
/** | ||
* \brief Class representing a UTC timestamp. | ||
*/ | ||
class UtcTimestamp : public ITimestamp { | ||
public: | ||
/** | ||
* \brief Constructor for UtcTimeStamp. | ||
* \param utc_timestamp The UTC timestamp in nanoseconds. | ||
*/ | ||
explicit UtcTimestamp(uint64_t utc_timestamp); | ||
|
||
[[nodiscard]] uint64_t GetTimeNs() const override; | ||
[[nodiscard]] int16_t GetTimezoneMin() const override; | ||
[[nodiscard]] int16_t GetDstMin() const override; | ||
[[nodiscard]] uint64_t GetUtcTimeNs() const override; | ||
|
||
private: | ||
uint64_t utc_timestamp_; ///< The UTC timestamp in nanoseconds. | ||
}; | ||
|
||
/** | ||
* \brief Class representing a local timestamp, with timezone and DST offset. | ||
*/ | ||
class LocalTimestamp : public ITimestamp { | ||
public: | ||
/** | ||
* \brief Constructor for LocalTimeStamp. | ||
* \param local_timestamp The local timestamp in nanoseconds, with timezone | ||
* and DST offset. | ||
*/ | ||
explicit LocalTimestamp(uint64_t local_timestamp); | ||
[[nodiscard]] uint64_t GetTimeNs() const override; | ||
[[nodiscard]] int16_t GetTimezoneMin() const override; | ||
[[nodiscard]] int16_t GetDstMin() const override; | ||
[[nodiscard]] uint64_t GetUtcTimeNs() const override; | ||
|
||
private: | ||
uint64_t local_timestamp_; ///< The local timestamp in nanoseconds, with | ||
///< timezone and DST offset. | ||
int16_t timezone_offset_min_ = 0; ///< The timezone offset in minutes. | ||
int16_t dst_offset_min_ = 0; ///< The daylight saving time offset in minutes. | ||
}; | ||
|
||
/** | ||
* \brief Class representing a timestamp with timezone information. | ||
*/ | ||
class TimezoneTimestamp : public ITimestamp { | ||
public: | ||
/** | ||
* \brief Constructor for TimezoneTimeStamp. | ||
* \param utc_timestamp The UTC timestamp in nanoseconds. | ||
* \param timezone_offset_min The timezone offset in minutes. | ||
* \param dst_offset_min The daylight saving time offset in minutes. | ||
*/ | ||
TimezoneTimestamp(uint64_t utc_timestamp, int16_t timezone_offset_min, | ||
int16_t dst_offset_min); | ||
[[nodiscard]] uint64_t GetTimeNs() const override; | ||
[[nodiscard]] int16_t GetTimezoneMin() const override; | ||
[[nodiscard]] int16_t GetDstMin() const override; | ||
[[nodiscard]] uint64_t GetUtcTimeNs() const override; | ||
|
||
private: | ||
uint64_t utc_timestamp_; ///< The UTC timestamp in nanoseconds. | ||
int16_t timezone_offset_min_; ///< The timezone offset in minutes. | ||
int16_t dst_offset_min_; ///< The daylight saving time offset in minutes. | ||
}; | ||
} // namespace mdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.