diff options
Diffstat (limited to 'i18npool/source/calendar/calendar_gregorian.cxx')
-rw-r--r-- | i18npool/source/calendar/calendar_gregorian.cxx | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/i18npool/source/calendar/calendar_gregorian.cxx b/i18npool/source/calendar/calendar_gregorian.cxx index 18676361027a..f3b228efc04e 100644 --- a/i18npool/source/calendar/calendar_gregorian.cxx +++ b/i18npool/source/calendar/calendar_gregorian.cxx @@ -167,6 +167,11 @@ Calendar_gregorian::init(const Era *_eraArray) * */ icu::Locale aIcuLocale( "", nullptr, nullptr, "calendar=gregorian"); + /* XXX: not specifying a timezone when creating a calendar assigns the + * system's timezone with all DST quirks, invalid times when switching + * to/from DST and so on. The XCalendar* interfaces are defined to support + * local time and UTC time so we can not override that here. + */ UErrorCode status = U_ZERO_ERROR; body.reset( icu::Calendar::createInstance( aIcuLocale, status) ); if (!body || !U_SUCCESS(status)) throw ERROR; @@ -369,6 +374,22 @@ Calendar_gregorian::getLocalDateTime() return (fTime + (nZoneOffset + nDSTOffset)) / U_MILLIS_PER_DAY; } +bool Calendar_gregorian::setTimeZone( const OUString& rTimeZone ) +{ + if (fieldSet) + { + setValue(); + getValue(); + } + const icu::UnicodeString aID( reinterpret_cast<const UChar*>(rTimeZone.getStr()), rTimeZone.getLength()); + const std::unique_ptr<const icu::TimeZone> pTZ( icu::TimeZone::createTimeZone(aID)); + if (!pTZ) + return false; + + body->setTimeZone(*pTZ); + return true; +} + // map field value from gregorian calendar to other calendar, it can be overwritten by derived class. // By using eraArray, it can take care Japanese and Taiwan ROC calendar. void Calendar_gregorian::mapFromGregorian() |