MDF Lib 2.2
Interface against MDF 3/4 files
Loading...
Searching...
No Matches
itimestamp.h
1#pragma once
2#include <string>
3
4namespace mdf {
5
6namespace timeunits {
7constexpr uint64_t kNanosecondsPerSecond = 1'000'000'000;
8constexpr uint64_t kNanosecondsPerMinute = 60 * kNanosecondsPerSecond;
9constexpr uint64_t kNanosecondsPerHour = 60 * kNanosecondsPerMinute;
10constexpr uint32_t kSecondsPerMinute = 60;
11constexpr uint32_t kSecondsPerHour = 60 * kSecondsPerMinute;
12} // namespace timeunits
13
18 public:
22 virtual ~ITimestamp() = default;
27 [[nodiscard]] virtual uint64_t GetTimeNs() const = 0;
32 [[nodiscard]] virtual int16_t GetTimezoneMin() const = 0;
37 [[nodiscard]] virtual int16_t GetDstMin() const = 0;
42 [[nodiscard]] virtual uint64_t GetUtcTimeNs() const = 0;
43};
44
48class UtcTimestamp : public ITimestamp {
49 public:
54 explicit UtcTimestamp(uint64_t utc_timestamp);
55
56 [[nodiscard]] uint64_t GetTimeNs() const override;
57 [[nodiscard]] int16_t GetTimezoneMin() const override;
58 [[nodiscard]] int16_t GetDstMin() const override;
59 [[nodiscard]] uint64_t GetUtcTimeNs() const override;
60
61 private:
62 uint64_t utc_timestamp_;
63};
64
68class LocalTimestamp : public ITimestamp {
69 public:
75 explicit LocalTimestamp(uint64_t local_timestamp);
76 [[nodiscard]] uint64_t GetTimeNs() const override;
77 [[nodiscard]] int16_t GetTimezoneMin() const override;
78 [[nodiscard]] int16_t GetDstMin() const override;
79 [[nodiscard]] uint64_t GetUtcTimeNs() const override;
80
81 private:
82 uint64_t local_timestamp_;
84 int16_t timezone_offset_min_ = 0;
85 int16_t dst_offset_min_ = 0;
86};
87
92 public:
99 TimezoneTimestamp(uint64_t utc_timestamp, int16_t timezone_offset_min,
100 int16_t dst_offset_min);
101 [[nodiscard]] uint64_t GetTimeNs() const override;
102 [[nodiscard]] int16_t GetTimezoneMin() const override;
103 [[nodiscard]] int16_t GetDstMin() const override;
104 [[nodiscard]] uint64_t GetUtcTimeNs() const override;
105
106 private:
107 uint64_t utc_timestamp_;
108 int16_t timezone_offset_min_;
109 int16_t dst_offset_min_;
110};
111} // namespace mdf
Interface for timestamp handling in MDF files.
Definition itimestamp.h:17
virtual int16_t GetDstMin() const =0
Get the daylight saving time offset in minutes.
virtual uint64_t GetTimeNs() const =0
Get the time in nanoseconds.
virtual ~ITimestamp()=default
Virtual destructor for ITimestamp.
virtual int16_t GetTimezoneMin() const =0
Get the timezone offset in minutes.
virtual uint64_t GetUtcTimeNs() const =0
Get the UTC time in nanoseconds.
Class representing a local timestamp, with timezone and DST offset.
Definition itimestamp.h:68
int16_t GetDstMin() const override
Get the daylight saving time offset in minutes.
uint64_t GetTimeNs() const override
Get the time in nanoseconds.
int16_t GetTimezoneMin() const override
Get the timezone offset in minutes.
LocalTimestamp(uint64_t local_timestamp)
Constructor for LocalTimeStamp.
uint64_t GetUtcTimeNs() const override
Get the UTC time in nanoseconds.
Class representing a timestamp with timezone information.
Definition itimestamp.h:91
int16_t GetDstMin() const override
Get the daylight saving time offset in minutes.
TimezoneTimestamp(uint64_t utc_timestamp, int16_t timezone_offset_min, int16_t dst_offset_min)
Constructor for TimezoneTimeStamp.
int16_t GetTimezoneMin() const override
Get the timezone offset in minutes.
uint64_t GetUtcTimeNs() const override
Get the UTC time in nanoseconds.
uint64_t GetTimeNs() const override
Get the time in nanoseconds.
Class representing a UTC timestamp.
Definition itimestamp.h:48
uint64_t GetUtcTimeNs() const override
Get the UTC time in nanoseconds.
UtcTimestamp(uint64_t utc_timestamp)
Constructor for UtcTimeStamp.
uint64_t GetTimeNs() const override
Get the time in nanoseconds.
int16_t GetTimezoneMin() const override
Get the timezone offset in minutes.
int16_t GetDstMin() const override
Get the daylight saving time offset in minutes.
Main namespace for the MDF library.
Definition canmessage.h:17