| 36 | } |
| 37 | |
| 38 | static inline int64_t GetSubSecond(const chrono::system_clock::time_point& t, |
| 39 | TimePrecision p) { |
| 40 | auto frac = t.time_since_epoch(); |
| 41 | if (p == TimePrecision::Millisecond) { |
| 42 | auto subsec = chrono::duration_cast<chrono::milliseconds>(frac) % MILLIS_PER_SEC; |
| 43 | return subsec.count(); |
| 44 | } else if (p == TimePrecision::Microsecond) { |
| 45 | auto subsec = chrono::duration_cast<chrono::microseconds>(frac) % MICROS_PER_SEC; |
| 46 | return subsec.count(); |
| 47 | } else if (p == TimePrecision::Nanosecond) { |
| 48 | auto subsec = chrono::duration_cast<chrono::nanoseconds>(frac) % NANOS_PER_SEC; |
| 49 | return subsec.count(); |
| 50 | } else { |
| 51 | return 0; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // Convert the given 'second' unix timestamp, into a date-time string in the |
| 56 | // UTC time zone if 'utc' is true, or the local time zone if it is false. |