17 #if QT_VERSION >= 0x050000 40 weekNo.setNum( week );
43 if ( weekNo.length() == 1 )
44 weekNoWW += QLatin1Char(
'0' );
49 fmt.replace( QLatin1String(
"ww" ), weekNoWW );
50 fmt.replace( QLatin1Char(
'w' ), weekNo );
52 if ( week == 1 && dateTime.date().month() != 1 )
56 QLatin1String s_yyyy(
"yyyy" );
57 QLatin1String s_yy(
"yy" );
61 bool doReplaceYear = fmt.contains( s_yy );
65 if ( fmt.contains(
'M' ) )
70 doReplaceYear =
false;
79 for (
int i = 0;
i < fmt.size();
i++ )
87 if ( numD > 0 && numD <= 2 )
94 if ( numD > 0 && numD <= 2 )
95 doReplaceYear =
false;
101 const QDate dt( dateTime.date().year() + 1, 1, 1 );
103 if ( fmt.contains( s_yyyy ) )
105 fmt.replace( s_yyyy, dt.toString( s_yyyy ) );
109 fmt.replace( s_yy, dt.toString( s_yyyy ) );
119 #if QT_VERSION >= 0x040800 120 return QLocale().firstDayOfWeek();
123 switch( QLocale().country() )
125 case QLocale::Maldives:
128 case QLocale::Afghanistan:
129 case QLocale::Algeria:
130 case QLocale::Bahrain:
131 case QLocale::Djibouti:
133 case QLocale::Eritrea:
134 case QLocale::Ethiopia:
137 case QLocale::Jordan:
139 case QLocale::Kuwait:
140 case QLocale::LibyanArabJamahiriya:
141 case QLocale::Morocco:
144 case QLocale::SaudiArabia:
145 case QLocale::Somalia:
147 case QLocale::Tunisia:
151 case QLocale::AmericanSamoa:
152 case QLocale::Argentina:
153 case QLocale::Azerbaijan:
154 case QLocale::Botswana:
155 case QLocale::Canada:
157 case QLocale::FaroeIslands:
158 case QLocale::Georgia:
159 case QLocale::Greenland:
161 case QLocale::HongKong:
162 case QLocale::Iceland:
164 case QLocale::Ireland:
165 case QLocale::Israel:
166 case QLocale::Jamaica:
168 case QLocale::Kyrgyzstan:
171 case QLocale::MarshallIslands:
173 case QLocale::Mongolia:
174 case QLocale::NewZealand:
175 case QLocale::NorthernMarianaIslands:
176 case QLocale::Pakistan:
177 case QLocale::Philippines:
178 case QLocale::RepublicOfKorea:
179 case QLocale::Singapore:
180 case QLocale::SyrianArabRepublic:
181 case QLocale::Taiwan:
182 case QLocale::Thailand:
183 case QLocale::TrinidadAndTobago:
184 case QLocale::UnitedStates:
185 case QLocale::UnitedStatesMinorOutlyingIslands:
186 case QLocale::USVirginIslands:
187 case QLocale::Uzbekistan:
188 case QLocale::Zimbabwe:
204 const Qt::TimeSpec timeSpec = dt.timeSpec();
206 if ( timeSpec == Qt::LocalTime )
207 dt = dt.toTimeSpec( Qt::UTC );
209 const QTime t = dt.time();
210 switch( intervalType )
214 dt.setTime( QTime( t.hour(), t.minute(), t.second() ) );
219 dt.setTime( QTime( t.hour(), t.minute(), 0 ) );
224 dt.setTime( QTime( t.hour(), 0, 0 ) );
231 if ( timeSpec == Qt::LocalTime )
232 dt = dt.toTimeSpec( Qt::LocalTime );
236 const QDateTime &dt, Qt::TimeSpec spec )
238 if ( dt.timeSpec() == spec )
241 const qint64 jd = dt.date().toJulianDay();
242 if ( jd < 0 || jd >= INT_MAX )
250 dt2.setTimeSpec( spec );
254 return dt.toTimeSpec( spec );
262 const int m1 = ( month - 14 ) / 12;
263 const int m2 = ( 367 * ( month - 2 - 12 * m1 ) ) / 12;
264 const double y1 = ::floor( ( 4900.0 + year + m1 ) / 100 );
266 return ::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2
267 - ::floor( ( 3 * y1 ) / 4 ) + day - 32075;
286 static inline QDate
qwtToDate(
int year,
int month = 1,
int day = 1 )
288 #if QT_VERSION >= 0x050000 289 return QDate( year, month, day );
296 const int m1 = ( month - 14 ) / 12;
297 const int m2 = ( 367 * ( month - 2 - 12 * m1 ) ) / 12;
298 const double y1 = ::floor( ( 4900.0 + year + m1 ) / 100 );
300 const double jd = ::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2
301 - ::floor( ( 3 * y1 ) / 4 ) + day - 32075;
305 qWarning() <<
"qwtToDate: overflow";
309 return QDate::fromJulianDay( static_cast<QwtJulianDay>( jd ) );
313 return QDate( year, month, day );
331 const int msecsPerDay = 86400000;
333 const double days =
static_cast<qint64
>(
::floor( value / msecsPerDay ) );
338 qWarning() <<
"QwtDate::toDateTime: overflow";
342 const QDate
d = QDate::fromJulianDay( static_cast<QwtJulianDay>( jd ) );
344 const int msecs =
static_cast<int>( value - days * msecsPerDay );
346 static const QTime timeNull( 0, 0, 0, 0 );
348 QDateTime dt( d, timeNull.addMSecs( msecs ), Qt::UTC );
350 if ( timeSpec == Qt::LocalTime )
368 const int msecsPerDay = 86400000;
374 const QTime time = dt.time();
375 const double secs = 3600.0 * time.hour() +
376 60.0 * time.minute() + time.second();
378 return days * msecsPerDay + time.msec() + 1000.0 * secs;
396 QDateTime dt = dateTime;
398 switch ( intervalType )
408 dt = dt.addSecs( 1 );
416 dt = dt.addSecs( 60 );
424 dt = dt.addSecs( 3600 );
430 dt.setTime( QTime( 0, 0 ) );
432 dt = dt.addDays( 1 );
438 dt.setTime( QTime( 0, 0 ) );
440 dt = dt.addDays( 1 );
446 dt = dt.addDays( days );
452 dt.setTime( QTime( 0, 0 ) );
453 dt.setDate(
qwtToDate( dateTime.date().year(),
454 dateTime.date().month() ) );
457 dt = dt.addMonths( 1 );
463 dt.setTime( QTime( 0, 0 ) );
465 const QDate
d = dateTime.date();
468 if ( d.month() > 1 || d.day() > 1 || !dateTime.time().isNull() )
499 QDateTime dt = dateTime;
501 switch ( intervalType )
516 dt.setTime( QTime( 0, 0 ) );
521 dt.setTime( QTime( 0, 0 ) );
527 dt = dt.addDays( -days );
533 dt.setTime( QTime( 0, 0 ) );
535 const QDate date =
qwtToDate( dt.date().year(),
543 dt.setTime( QTime( 0, 0 ) );
545 const QDate date =
qwtToDate( dt.date().year() );
570 if ( !date.isValid() )
592 if ( !date.isValid() )
614 QDate dt0( year, 1, 1 );
617 int days = dt0.dayOfWeek() - firstDayOfWeek;
621 dt0 = dt0.addDays( -days );
628 int d = Qt::Thursday - firstDayOfWeek;
632 if ( dt0.addDays( d ).year() < year )
633 dt0 = dt0.addDays( 7 );
661 if ( date.month() == 12 && date.day() >= 24 )
667 if ( day0.daysTo( date ) < 0 )
675 weekNo = day0.daysTo( date ) / 7 + 1;
679 weekNo = date.weekNumber();
707 switch( dateTime.timeSpec() )
713 case Qt::OffsetFromUTC:
715 seconds = dateTime.utcOffset();
720 const QDateTime dt1( dateTime.date(), dateTime.time(), Qt::UTC );
721 seconds = dateTime.secsTo( dt1 );
751 const QString & format,
Week0Type week0Type )
753 QString fmt = format;
754 if ( fmt.contains(
'w' ) )
759 return dateTime.toString( fmt );
static Qt::DayOfWeek qwtFirstDayOfWeek()
The interval is related to weeks.
The interval is related to years.
The interval is related to months.
static QDateTime qwtToTimeSpec(const QDateTime &dt, Qt::TimeSpec spec)
static QDateTime floor(const QDateTime &, IntervalType)
static double toDouble(const QDateTime &)
static const QwtJulianDay maxJulianDayD
std::chrono::duration< std::int_fast64_t > seconds
The interval is related to minutes.
static const QwtJulianDay minJulianDayD
The interval is related to hours.
static qint64 qwtFloorDiv64(qint64 a, int b)
static int utcOffset(const QDateTime &)
The Julian day of "The Epoch".
The interval is related to milliseconds.
static QDateTime ceil(const QDateTime &, IntervalType)
static QString qwtExpandedFormat(const QString &format, const QDateTime &dateTime, QwtDate::Week0Type week0Type)
static int weekNumber(const QDate &, Week0Type)
static QDate dateOfWeek0(int year, Week0Type)
Date of the first day of the first week for a year.
static QDateTime toDateTime(double value, Qt::TimeSpec=Qt::UTC)
static double qwtToJulianDay(int year, int month, int day)
static QString toString(const QDateTime &, const QString &format, Week0Type)
The interval is related to seconds.
static void qwtFloorTime(QwtDate::IntervalType intervalType, QDateTime &dt)
static qint64 qwtFloorDiv(int a, int b)
static QDate qwtToDate(int year, int month=1, int day=1)
The interval is related to days.