/** * call-seq: * calendar.in_daylight_time? * * Determine if a UCalendar is currently in daylight savings time. * * Daylight savings time is not used in all parts of the world */ VALUE icu4r_cal_in_daylight(VALUE obj) { UErrorCode status = U_ZERO_ERROR; int32_t answer; answer = ucal_inDaylightTime(UCALENDAR(obj), &status); ICU_RAISE(status); return answer ? Qtrue : Qfalse; }
static Variant HHVM_METHOD(IntlDateFormatter, localtime, const String& value, VRefParam position) { DATFMT_GET(data, this_, uninit_null()); int32_t parse_pos = -1; if (!position.isNull()) { parse_pos = position.toInt64(); if (parse_pos > value.size()) { return false; } } UErrorCode error = U_ZERO_ERROR; String uValue(u16(value, error)); if (U_FAILURE(error)) { data->setError(error, "Error converting timezone to UTF-16"); return false; } error = U_ZERO_ERROR; UCalendar *cal = const_cast<UCalendar*>(udat_getCalendar(data->datefmt())); udat_parseCalendar(data->datefmt(), cal, (UChar*)uValue.c_str(), uValue.size() / sizeof(UChar), &parse_pos, &error); Array ret = Array::Create(); error = U_ZERO_ERROR; add_to_localtime_arr(ret, cal, UCAL_SECOND, s_tm_sec, error); add_to_localtime_arr(ret, cal, UCAL_MINUTE, s_tm_min, error); add_to_localtime_arr(ret, cal, UCAL_HOUR_OF_DAY, s_tm_hour, error); add_to_localtime_arr(ret, cal, UCAL_YEAR, s_tm_year, error, -1900); add_to_localtime_arr(ret, cal, UCAL_DAY_OF_MONTH, s_tm_mday, error); add_to_localtime_arr(ret, cal, UCAL_DAY_OF_WEEK, s_tm_wday, error, -1); add_to_localtime_arr(ret, cal, UCAL_DAY_OF_YEAR, s_tm_yday, error); add_to_localtime_arr(ret, cal, UCAL_MONTH, s_tm_mon, error); if (U_FAILURE(error)) { data->setError(error, "Date parsing - localtime failed : " "could not get a field from calendar"); return false; } error = U_ZERO_ERROR; auto isDST = ucal_inDaylightTime(cal, &error); if (U_FAILURE(error)) { data->setError(error, "Date parsing - localtime failed : " "while checking if currently in DST."); return false; } ret.set(s_tm_isdst, isDST ? 1 : 0); position = (int64_t)parse_pos; return ret; }
bool QIcuTimeZonePrivate::isDaylightTime(qint64 atMSecsSinceEpoch) const { // Clone the ucal so we don't change the shared object UErrorCode status = U_ZERO_ERROR; UCalendar *ucal = ucal_clone(m_ucal, &status); if (!U_SUCCESS(status)) return false; // Set the date to find the offset for status = U_ZERO_ERROR; ucal_setMillis(ucal, atMSecsSinceEpoch, &status); bool result = false; if (U_SUCCESS(status)) { status = U_ZERO_ERROR; result = ucal_inDaylightTime(ucal, &status); } ucal_close(ucal); return result; }
/* {{{ * Internal function which calls the udat_parseCalendar */ static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* text_to_parse, int32_t text_len, int32_t *parse_pos, zval *return_value) { UCalendar *parsed_calendar = NULL; UChar* text_utf16 = NULL; int32_t text_utf16_len = 0; zend_long isInDST = 0; /* Convert timezone to UTF-16. */ intl_convert_utf8_to_utf16(&text_utf16, &text_utf16_len, text_to_parse, text_len, &INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS(dfo, "Error converting timezone to UTF-16" ); parsed_calendar = (UCalendar *)udat_getCalendar(DATE_FORMAT_OBJECT(dfo)); udat_parseCalendar( DATE_FORMAT_OBJECT(dfo), parsed_calendar, text_utf16, text_utf16_len, parse_pos, &INTL_DATA_ERROR_CODE(dfo)); if (text_utf16) { efree(text_utf16); } INTL_METHOD_CHECK_STATUS( dfo, "Date parsing failed" ); array_init( return_value ); /* Add entries from various fields of the obtained parsed_calendar */ add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_SECOND, CALENDAR_SEC); add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_MINUTE, CALENDAR_MIN); add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_HOUR_OF_DAY, CALENDAR_HOUR); add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_YEAR, CALENDAR_YEAR); add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_DAY_OF_MONTH, CALENDAR_MDAY); add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_DAY_OF_WEEK, CALENDAR_WDAY); add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_DAY_OF_YEAR, CALENDAR_YDAY); add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_MONTH, CALENDAR_MON); /* Is in DST? */ isInDST = ucal_inDaylightTime(parsed_calendar , &INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS( dfo, "Date parsing - localtime failed : while checking if currently in DST." ); add_assoc_long( return_value, CALENDAR_ISDST,(isInDST==1?1:0)); }