9#include <unicode/ucal.h>
31 UErrorCode status = U_ZERO_ERROR;
34 size = ucal_getDefaultTimeZone(
reinterpret_cast<UChar *
>(
result.data()),
size, &status);
37 if (status == U_BUFFER_OVERFLOW_ERROR) {
39 status = U_ZERO_ERROR;
40 size = ucal_getDefaultTimeZone(
reinterpret_cast<UChar *
>(
result.data()),
size, &status);
44 if (U_SUCCESS(status)) {
46 return std::move(
result).toUtf8();
54 int *utcOffset,
int *dstOffset)
60 UErrorCode status = U_ZERO_ERROR;
61 UCalendar *ucal = ucal_clone(m_ucal, &status);
62 if (!U_SUCCESS(status))
66 status = U_ZERO_ERROR;
67 ucal_setMillis(ucal, atMSecsSinceEpoch, &status);
70 if (U_SUCCESS(status)) {
71 status = U_ZERO_ERROR;
73 utc = ucal_get(ucal, UCAL_ZONE_OFFSET, &status) / 1000;
77 if (U_SUCCESS(status)) {
78 status = U_ZERO_ERROR;
80 dst = ucal_get(ucal, UCAL_DST_OFFSET, &status) / 1000;
84 if (U_SUCCESS(status)) {
92#if U_ICU_VERSION_MAJOR_NUM >= 50
95 UTimeZoneTransitionType
type,
101 UErrorCode status = U_ZERO_ERROR;
102 UCalendar *ucal = ucal_clone(m_ucal, &status);
103 if (!U_SUCCESS(status))
107 status = U_ZERO_ERROR;
108 ucal_setMillis(ucal, atMSecsSinceEpoch, &status);
112 status = U_ZERO_ERROR;
113 bool ok = ucal_getTimeZoneTransitionDate(ucal,
type, &tranMSecs, &status);
116 if (U_SUCCESS(status) &&
ok &&
type == UCAL_TZ_TRANSITION_NEXT) {
120 ok =
qint64(tranMSecs) > atMSecsSinceEpoch;
124 if (U_SUCCESS(status) &&
ok) {
125 status = U_ZERO_ERROR;
126 ucal_setMillis(ucal, tranMSecs, &status);
130 if (U_SUCCESS(status) &&
ok) {
131 status = U_ZERO_ERROR;
132 utc = ucal_get(ucal, UCAL_ZONE_OFFSET, &status) / 1000;
136 if (U_SUCCESS(status) &&
ok) {
137 status = U_ZERO_ERROR;
138 dst = ucal_get(ucal, UCAL_DST_OFFSET, &status) / 1000;
142 if (!U_SUCCESS(status) || !
ok)
144 tran.atMSecsSinceEpoch = tranMSecs;
145 tran.offsetFromUtc = utc +
dst;
146 tran.standardTimeOffset = utc;
147 tran.daylightTimeOffset =
dst;
149 QTimeZone::TimeType timeType =
dst == 0 ? QTimeZone::StandardTime : QTimeZone::DaylightTime;
151 tran.abbreviation = ucalTimeZoneDisplayName(m_ucal, timeType,
160 QList<QByteArray>
list;
162 UErrorCode status = U_ZERO_ERROR;
165 while (U_SUCCESS(status) && !
result.isEmpty()) {
167 status = U_ZERO_ERROR;
178 UErrorCode status = U_ZERO_ERROR;
180 const int32_t dstMSecs = ucal_getDSTSavings(
181 reinterpret_cast<const UChar *
>(utf16.
data()), &status);
182 return U_SUCCESS(status) ? dstMSecs / 1000 : 0;
186QIcuTimeZonePrivate::QIcuTimeZonePrivate()
194QIcuTimeZonePrivate::QIcuTimeZonePrivate(
const QByteArray &ianaId)
198 if (isTimeZoneIdAvailable(ianaId))
202QIcuTimeZonePrivate::QIcuTimeZonePrivate(
const QIcuTimeZonePrivate &
other)
206 UErrorCode status = U_ZERO_ERROR;
207 m_ucal = ucal_clone(
other.m_ucal, &status);
208 if (!U_SUCCESS(status)) {
214QIcuTimeZonePrivate::~QIcuTimeZonePrivate()
219QIcuTimeZonePrivate *QIcuTimeZonePrivate::clone()
const
221 return new QIcuTimeZonePrivate(*
this);
224void QIcuTimeZonePrivate::init(
const QByteArray &ianaId)
229 UErrorCode status = U_ZERO_ERROR;
231 m_ucal = ucal_open(
reinterpret_cast<const UChar *
>(
id.
data()),
id.
size(),
234 if (!U_SUCCESS(status)) {
240QString QIcuTimeZonePrivate::displayName(QTimeZone::TimeType timeType,
241 QTimeZone::NameType nameType,
245 if (nameType == QTimeZone::OffsetName) {
249 if (timeType == QTimeZone::DaylightTime)
256 return isoOffsetFormat(
offset);
261 return ucalTimeZoneDisplayName(m_ucal, timeType, nameType,
locale.name());
264int QIcuTimeZonePrivate::offsetFromUtc(
qint64 atMSecsSinceEpoch)
const
269 return stdOffset + dstOffset;
272int QIcuTimeZonePrivate::standardTimeOffset(
qint64 atMSecsSinceEpoch)
const
280int QIcuTimeZonePrivate::daylightTimeOffset(
qint64 atMSecsSinceEpoch)
const
288bool QIcuTimeZonePrivate::hasDaylightTime()
const
292#if U_ICU_VERSION_MAJOR_NUM >= 50
293 for (
qint64 when = minMSecs(); when != invalidMSecs(); ) {
294 auto data = nextTransition(when);
295 if (
data.daylightTimeOffset &&
data.daylightTimeOffset != invalidSeconds())
297 when =
data.atMSecsSinceEpoch;
303bool QIcuTimeZonePrivate::isDaylightTime(
qint64 atMSecsSinceEpoch)
const
306 UErrorCode status = U_ZERO_ERROR;
307 UCalendar *ucal = ucal_clone(m_ucal, &status);
308 if (!U_SUCCESS(status))
312 status = U_ZERO_ERROR;
313 ucal_setMillis(ucal, atMSecsSinceEpoch, &status);
316 if (U_SUCCESS(status)) {
317 status = U_ZERO_ERROR;
318 result = ucal_inDaylightTime(ucal, &status);
329#if U_ICU_VERSION_MAJOR_NUM >= 50
330 data = ucalTimeZoneTransition(m_ucal, UCAL_TZ_TRANSITION_PREVIOUS_INCLUSIVE,
332 if (
data.atMSecsSinceEpoch == invalidMSecs())
336 &
data.daylightTimeOffset);
337 data.offsetFromUtc =
data.standardTimeOffset +
data.daylightTimeOffset;
338 data.abbreviation = abbreviation(forMSecsSinceEpoch);
340 data.atMSecsSinceEpoch = forMSecsSinceEpoch;
344bool QIcuTimeZonePrivate::hasTransitions()
const
347#if U_ICU_VERSION_MAJOR_NUM >= 50
357#if U_ICU_VERSION_MAJOR_NUM >= 50
358 return ucalTimeZoneTransition(m_ucal, UCAL_TZ_TRANSITION_NEXT, afterMSecsSinceEpoch);
368#if U_ICU_VERSION_MAJOR_NUM >= 50
369 return ucalTimeZoneTransition(m_ucal, UCAL_TZ_TRANSITION_PREVIOUS, beforeMSecsSinceEpoch);
376QByteArray QIcuTimeZonePrivate::systemTimeZoneId()
const
383bool QIcuTimeZonePrivate::isTimeZoneIdAvailable(
const QByteArray &ianaId)
const
386 const UChar *
const name =
reinterpret_cast<const UChar *
>(ianaStr.constData());
389 constexpr size_t size = 64;
394 UErrorCode status = U_ZERO_ERROR;
397 ucal_getCanonicalTimeZoneID(
name, ianaStr.size(),
buffer,
size, &isSys, &status);
402QList<QByteArray> QIcuTimeZonePrivate::availableTimeZoneIds()
const
404 UErrorCode status = U_ZERO_ERROR;
405 UEnumeration *uenum = ucal_openTimeZones(&status);
407 if (U_SUCCESS(status))
413QList<QByteArray> QIcuTimeZonePrivate::availableTimeZoneIds(
QLocale::Territory territory)
const
417 UErrorCode status = U_ZERO_ERROR;
418 UEnumeration *uenum = ucal_openCountryTimeZones(regionCodeUtf8.data(), &status);
420 if (U_SUCCESS(status))
426QList<QByteArray> QIcuTimeZonePrivate::availableTimeZoneIds(
int offsetFromUtc)
const
429#if U_ICU_VERSION_MAJOR_NUM >= 49 || (U_ICU_VERSION_MAJOR_NUM == 4 && U_ICU_VERSION_MINOR_NUM == 8)
430 UErrorCode status = U_ZERO_ERROR;
431 UEnumeration *uenum = ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY,
nullptr,
432 &offsetFromUtc, &status);
434 if (U_SUCCESS(status))
static qint64 currentMSecsSinceEpoch() noexcept
iterator erase(const_iterator begin, const_iterator end)
static QLatin1StringView territoryToCode(QLocale::Territory territory)
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QChar * data()
Returns a pointer to the data stored in the QString.
QByteArray toUtf8() const &
virtual QList< QByteArray > availableTimeZoneIds() const
Q_QML_EXPORT QV4::ReturnedValue locale(QV4::ExecutionEngine *engine, const QString &localeName)
Provides locale specific properties and formatted data.
Combined button and popup list for selecting options.
int toUtf8(char16_t u, OutputPtr &dst, InputPtr &src, InputPtr end)
constexpr Initialization Uninitialized
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
static bool ucalOffsetsAtTime(UCalendar *m_ucal, qint64 atMSecsSinceEpoch, int *utcOffset, int *dstOffset)
static int ucalDaylightOffset(const QByteArray &id)
static QList< QByteArray > uenumToIdList(UEnumeration *uenum)
static QT_BEGIN_NAMESPACE QByteArray ucalDefaultTimeZoneId()