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/KM_util.cpp | |
| 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/KM_util.cpp')
| -rwxr-xr-x | src/KM_util.cpp | 62 |
1 files changed, 52 insertions, 10 deletions
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++; } } |
