From 55e9d7f9fd598b1bfb9ee46ea0cfc971f88dd800 Mon Sep 17 00:00:00 2001 From: msheby Date: Sat, 28 Mar 2009 04:42:36 +0000 Subject: 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. --- src/KM_util.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 10 deletions(-) (limited to 'src/KM_util.cpp') 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++; } } -- cgit v1.2.3