Represents either a (1) date and time, (2) a date with an undefined time, or (3) a time with an undefined date. In all cases, times have up to nanosecond resolution and the minimum and maximum dates are 1400-01-01 and 9999-12-31. This type is similar to Postgresql TIMESTAMP WITHOUT TIME ZONE datatype and MySQL's DATETIME datatype. Note that because TIMESTAMP does not contain time zone information
| 71 | /// Also keep in mind that the time component rolls over at midnight so the date should |
| 72 | /// always be checked when determining a duration. |
| 73 | class TimestampValue { |
| 74 | public: |
| 75 | TimestampValue() {} |
| 76 | |
| 77 | TimestampValue(const boost::gregorian::date& d, |
| 78 | const boost::posix_time::time_duration& t) |
| 79 | : time_(t), |
| 80 | date_(d) { |
| 81 | Validate(); |
| 82 | } |
| 83 | TimestampValue(const boost::posix_time::ptime& t) |
| 84 | : time_(t.time_of_day()), |
| 85 | date_(t.date()) { |
| 86 | Validate(); |
| 87 | } |
| 88 | TimestampValue(const TimestampValue& tv) : time_(tv.time_), date_(tv.date_) {} |
| 89 | |
| 90 | /// Constructors that parse from a date/time string. See TimestampParser for details |
| 91 | /// about the date-time format. |
| 92 | static TimestampValue ParseSimpleDateFormat(const std::string& str); |
| 93 | static TimestampValue ParseSimpleDateFormat(const char* str, int len); |
| 94 | static TimestampValue ParseSimpleDateFormat(const char* str, int len, |
| 95 | const datetime_parse_util::DateTimeFormatContext& dt_ctx); |
| 96 | static TimestampValue ParseIsoSqlFormat(const char* str, int len, |
| 97 | const datetime_parse_util::DateTimeFormatContext& dt_ctx); |
| 98 | |
| 99 | /// 'days' represents the number of days since 1970-01-01. |
| 100 | /// The returned timestamp's date component is set so that it would correspond to |
| 101 | /// 'days', the time-of-day component is set to 00:00:00. |
| 102 | static TimestampValue FromDaysSinceUnixEpoch(int64_t days); |
| 103 | |
| 104 | // Returns the number of days since 1970-01-01. Expects date_ to be valid. |
| 105 | int64_t DaysSinceUnixEpoch() const; |
| 106 | |
| 107 | /// Unix time (seconds since 1970-01-01 UTC by definition) constructors. |
| 108 | /// If 'local_tz' is set and non-UTC, 'unix_time' is assumed to be UTC and |
| 109 | /// UTC->local_tz conversion takes place. |
| 110 | static TimestampValue FromUnixTime(time_t unix_time, const Timezone* local_tz); |
| 111 | |
| 112 | /// Same as FromUnixTime() above, but adds the specified number of nanoseconds to the |
| 113 | /// resulting TimestampValue. Handles negative nanoseconds and the case where |
| 114 | /// abs(nanos) >= 1e9. |
| 115 | static TimestampValue FromUnixTimeNanos(time_t unix_time, int64_t nanos, |
| 116 | const Timezone* local_tz); |
| 117 | |
| 118 | /// Same as FromUnixTime(), but expects the time in microseconds. |
| 119 | static TimestampValue FromUnixTimeMicros(int64_t unix_time_micros, |
| 120 | const Timezone* local_tz); |
| 121 | |
| 122 | /// Return the corresponding timestamp in UTC for the Unix time specified in |
| 123 | /// nanoseconds. The range is smaller than in other conversion function, as the |
| 124 | /// full [1400 .. 10000) range cannot be represented with an int64. |
| 125 | /// Supported range: [1677-09-21 00:12:43.145224192 .. 2262-04-11 23:47:16.854775807] |
| 126 | static TimestampValue UtcFromUnixTimeLimitedRangeNanos(int64_t unix_time_nanos); |
| 127 | |
| 128 | /// Return the corresponding timestamp in UTC for the Unix time specified in |
| 129 | /// microseconds. |
| 130 | static TimestampValue UtcFromUnixTimeMicros(int64_t unix_time_micros); |
no test coverage detected