diff options
| author | msheby <msheby@cinecert.com> | 2009-03-28 04:42:36 +0000 |
|---|---|---|
| committer | msheby <> | 2009-03-28 04:42:36 +0000 |
| commit | 55e9d7f9fd598b1bfb9ee46ea0cfc971f88dd800 (patch) | |
| tree | 876ad4c9f73dbf00322aa18e0e099985e3410ada /src | |
| parent | 213c1015cd54bd3539a7e28fd004419dcf31e007 (diff) | |
Add AddMinutes() function.
Allow negative input to AddHours() and AddDays() in Windows implementation.
Allow parsing of non-zero minutes in time offset values.
Allow parsing of "Z" as time offset value.
Diffstat (limited to 'src')
| -rw-r--r-- | src/KM_tai.h | 3 | ||||
| -rwxr-xr-x | src/KM_util.cpp | 62 | ||||
| -rwxr-xr-x | src/KM_util.h | 7 |
3 files changed, 58 insertions, 14 deletions
diff --git a/src/KM_tai.h b/src/KM_tai.h index 6495dbd..09c85d2 100644 --- a/src/KM_tai.h +++ b/src/KM_tai.h @@ -64,8 +64,9 @@ namespace Kumu struct tai { ui64_t x; + inline void add_minutes(i32_t m) { x += m * 60; } inline void add_hours(i32_t h) { x += h * 3600; } - inline void add_days(i32_t h) { x += h * 86400; } + inline void add_days(i32_t d) { x += d * 86400; } void now(); const tai& operator=(const caltime& rhs); diff --git a/src/KM_util.cpp b/src/KM_util.cpp index e426afc..391394c 100755 --- a/src/KM_util.cpp +++ b/src/KM_util.cpp @@ -727,7 +727,7 @@ Kumu::Timestamp::AddDays(i32_t days) TIMESTAMP_TO_SYSTIME(*this, ¤t_st); SystemTimeToFileTime(¤t_st, ¤t_ft); memcpy(¤t_ul, ¤t_ft, sizeof(current_ul)); - current_ul.QuadPart += ( seconds_to_ns100(86400) * (ui64_t)days ); + current_ul.QuadPart += ( seconds_to_ns100(86400) * (i64_t)days ); memcpy(¤t_ft, ¤t_ul, sizeof(current_ft)); FileTimeToSystemTime(¤t_ft, ¤t_st); SYSTIME_TO_TIMESTAMP(¤t_st, *this); @@ -747,7 +747,27 @@ Kumu::Timestamp::AddHours(i32_t hours) TIMESTAMP_TO_SYSTIME(*this, ¤t_st); SystemTimeToFileTime(¤t_st, ¤t_ft); memcpy(¤t_ul, ¤t_ft, sizeof(current_ul)); - current_ul.QuadPart += ( seconds_to_ns100(3600) * (ui64_t)hours ); + current_ul.QuadPart += ( seconds_to_ns100(3600) * (i64_t)hours ); + memcpy(¤t_ft, ¤t_ul, sizeof(current_ft)); + FileTimeToSystemTime(¤t_ft, ¤t_st); + SYSTIME_TO_TIMESTAMP(¤t_st, *this); + } +} + +// +void +Kumu::Timestamp::AddMinutes(i32_t minutes) +{ + SYSTEMTIME current_st; + FILETIME current_ft; + ULARGE_INTEGER current_ul; + + if ( minutes != 0 ) + { + TIMESTAMP_TO_SYSTIME(*this, ¤t_st); + SystemTimeToFileTime(¤t_st, ¤t_ft); + memcpy(¤t_ul, ¤t_ft, sizeof(current_ul)); + current_ul.QuadPart += ( seconds_to_ns100(60) * (i64_t)minutes ); memcpy(¤t_ft, ¤t_ul, sizeof(current_ft)); FileTimeToSystemTime(¤t_ft, ¤t_st); SYSTIME_TO_TIMESTAMP(¤t_st, *this); @@ -852,6 +872,23 @@ Kumu::Timestamp::AddHours(i32_t hours) } } +// +void +Kumu::Timestamp::AddMinutes(i32_t minutes) +{ + Kumu::TAI::caltime ct; + Kumu::TAI::tai t; + + if ( minutes != 0 ) + { + TIMESTAMP_TO_CALTIME(*this, &ct) + t = ct; + t.add_minutes(minutes); + ct = t; + CALTIME_TO_TIMESTAMP(&ct, *this) + } +} + #endif // KM_WIN32 @@ -983,17 +1020,22 @@ Kumu::Timestamp::DecodeString(const char* datestr) return false; char_count += 6; - ui32_t TZ_hh = atoi(datestr + 20); - ui32_t TZ_mm = atoi(datestr + 23); - - if ( TZ_mm != 0 ) - Kumu::DefaultLogSink().Warn("Ignoring minutes in timezone offset: %u\n", TZ_mm); - - if ( TZ_hh > 12 ) + + i32_t TZ_mm = 60 * atoi(datestr + 20); + TZ_mm += atoi(datestr + 23); + if (datestr[19] == '-') + TZ_mm = -TZ_mm; + + if ((TZ_mm > 14 * 60) || (TZ_mm < -12 * 60)) return false; else - AddHours( (datestr[19] == '-' ? (0 - TZ_hh) : TZ_hh)); + TmpStamp.AddMinutes(-TZ_mm); + } + else if (datestr[19] == 'Z') + { + /* act as if the offset were +00:00 */ + char_count++; } } diff --git a/src/KM_util.h b/src/KM_util.h index d8b9bb3..8dd573f 100755 --- a/src/KM_util.h +++ b/src/KM_util.h @@ -362,7 +362,7 @@ namespace Kumu void GenRandomValue(SymmetricKey&); // - // 2004-05-01T13:20:00-00:00 + // 2004-05-01T13:20:00+00:00 const ui32_t DateTimeLen = 25; // the number of chars in the xs:dateTime format (sans milliseconds) // UTC time+date representation @@ -387,17 +387,18 @@ namespace Kumu bool operator==(const Timestamp& rhs) const; bool operator!=(const Timestamp& rhs) const; - // Write the timestamp value to the given buffer in the form 2004-05-01T13:20:00-00:00 + // Write the timestamp value to the given buffer in the form 2004-05-01T13:20:00+00:00 // returns 0 if the buffer is smaller than DateTimeLen const char* EncodeString(char* str_buf, ui32_t buf_len) const; // decode and set value from string formatted by EncodeString bool DecodeString(const char* datestr); - // Add the given number of days or hours to the timestamp value. + // Add the given number of days, hours, or minutes to the timestamp value. // Values less than zero will cause the timestamp to decrease void AddDays(i32_t); void AddHours(i32_t); + void AddMinutes(i32_t); // Read and write the timestamp value as a byte string having // the following format: |
