Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_date.cpp


Ignore:
Timestamp:
Nov 3, 2026, 10:53:35 AM (3 weeks ago)
Author:
stuerze
Message:

deprecated functions exchanged libs updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwt/qwt_date.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#include "qwt_date.h"
     11#include "qwt_math.h"
     12
    1113#include <qdebug.h>
    1214#include <qlocale.h>
    13 #include <math.h>
     15
    1416#include <limits>
    15 #include <limits.h>
    1617
    1718#if QT_VERSION >= 0x050000
    … …  
    2425
    2526// QDate stores the Julian day as unsigned int, but
    26 // but it is QDate::fromJulianDay( int ). That's why
     27// there is QDate::fromJulianDay( int ). That's why
    2728// we have the range [ 1, INT_MAX ]
     29
    2830typedef int QwtJulianDay;
    2931static const QwtJulianDay minJulianDayD = 1;
    30 static const QwtJulianDay maxJulianDayD = std::numeric_limits<int>::max();
     32static const QwtJulianDay maxJulianDayD = std::numeric_limits< int >::max();
    3133
    3234#endif
    3335
    34 static QString qwtExpandedFormat( const QString & format,
    35     const QDateTime &dateTime, QwtDate::Week0Type week0Type )
     36static QString qwtExpandedFormat( const QString& format,
     37    const QDateTime& dateTime, QwtDate::Week0Type week0Type )
    3638{
    3739    const int week = QwtDate::weekNumber( dateTime.date(), week0Type );
    … …  
    4244    QString weekNoWW;
    4345    if ( weekNo.length() == 1 )
    44         weekNoWW += "0";
     46        weekNoWW += QLatin1Char( '0' );
    4547
    4648    weekNoWW += weekNo;
    4749
    4850    QString fmt = format;
    49     fmt.replace( "ww", weekNoWW );
    50     fmt.replace( "w", weekNo );
     51    fmt.replace( QLatin1String( "ww" ), weekNoWW );
     52    fmt.replace( QLatin1Char( 'w' ), weekNo );
    5153
    5254    if ( week == 1 && dateTime.date().month() != 1 )
    … …  
    5456        // in case of week 1, we might need to increment the year
    5557
    56         static QString s_yyyy = "yyyy";
    57         static QString s_yy = "yy";
     58        QLatin1String s_yyyy( "yyyy" );
     59        QLatin1String s_yy( "yy" );
    5860
    5961        // week 1 might start in the previous year
    … …  
    100102        {
    101103            const QDate dt( dateTime.date().year() + 1, 1, 1 );
     104            const QString dtString = QLocale().toString( dt, s_yyyy );
    102105
    103106            if ( fmt.contains( s_yyyy ) )
    104107            {
    105                 fmt.replace( s_yyyy, dt.toString( s_yyyy ) );
     108                fmt.replace( s_yyyy, dtString );
    106109            }
    107110            else
    108111            {
    109                 fmt.replace( s_yy, dt.toString( s_yyyy ) );
     112                fmt.replace( s_yy, dtString );
    110113            }
    111114        }
    … …  
    117120static inline Qt::DayOfWeek qwtFirstDayOfWeek()
    118121{
    119 #if QT_VERSION >= 0x040800
    120122    return QLocale().firstDayOfWeek();
    121 #else
    122 
    123     switch( QLocale().country() )
    124     {
    125         case QLocale::Maldives:
    126             return Qt::Friday;
    127 
    128         case QLocale::Afghanistan:
    129         case QLocale::Algeria:
    130         case QLocale::Bahrain:
    131         case QLocale::Djibouti:
    132         case QLocale::Egypt:
    133         case QLocale::Eritrea:
    134         case QLocale::Ethiopia:
    135         case QLocale::Iran:
    136         case QLocale::Iraq:
    137         case QLocale::Jordan:
    138         case QLocale::Kenya:
    139         case QLocale::Kuwait:
    140         case QLocale::LibyanArabJamahiriya:
    141         case QLocale::Morocco:
    142         case QLocale::Oman:
    143         case QLocale::Qatar:
    144         case QLocale::SaudiArabia:
    145         case QLocale::Somalia:
    146         case QLocale::Sudan:
    147         case QLocale::Tunisia:
    148         case QLocale::Yemen:
    149             return Qt::Saturday;
    150 
    151         case QLocale::AmericanSamoa:
    152         case QLocale::Argentina:
    153         case QLocale::Azerbaijan:
    154         case QLocale::Botswana:
    155         case QLocale::Canada:
    156         case QLocale::China:
    157         case QLocale::FaroeIslands:
    158         case QLocale::Georgia:
    159         case QLocale::Greenland:
    160         case QLocale::Guam:
    161         case QLocale::HongKong:
    162         case QLocale::Iceland:
    163         case QLocale::India:
    164         case QLocale::Ireland:
    165         case QLocale::Israel:
    166         case QLocale::Jamaica:
    167         case QLocale::Japan:
    168         case QLocale::Kyrgyzstan:
    169         case QLocale::Lao:
    170         case QLocale::Malta:
    171         case QLocale::MarshallIslands:
    172         case QLocale::Macau:
    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:
    189             return Qt::Sunday;
    190 
    191         default:
    192             return Qt::Monday;
    193     }
    194 #endif
    195123}
    196124
    197125static inline void qwtFloorTime(
    198     QwtDate::IntervalType intervalType, QDateTime &dt )
     126    QwtDate::IntervalType intervalType, QDateTime& dt )
    199127{
    200128    // when dt is inside the special hour where DST is ending
    … …  
    234162
    235163static inline QDateTime qwtToTimeSpec(
    236     const QDateTime &dt, Qt::TimeSpec spec )
     164    const QDateTime& dt, Qt::TimeSpec spec )
    237165{
    238166    if ( dt.timeSpec() == spec )
    … …  
    240168
    241169    const qint64 jd = dt.date().toJulianDay();
    242     if ( jd < 0 || jd >= INT_MAX )
     170    if ( jd < 0 || jd >= std::numeric_limits< int >::max() )
    243171    {
    244172        // the conversion between local time and UTC
    … …  
    264192    const int m1 = ( month - 14 ) / 12;
    265193    const int m2 = ( 367 * ( month - 2 - 12 * m1 ) ) / 12;
    266     const double y1 = ::floor( ( 4900.0 + year + m1 ) / 100 );
    267 
    268     return ::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2
    269             - ::floor( ( 3 * y1 ) / 4 ) + day - 32075;
     194    const double y1 = std::floor( ( 4900.0 + year + m1 ) / 100 );
     195
     196    return std::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2
     197           - std::floor( ( 3 * y1 ) / 4 ) + day - 32075;
    270198}
    271199
    … …  
    300228        const int m1 = ( month - 14 ) / 12;
    301229        const int m2 = ( 367 * ( month - 2 - 12 * m1 ) ) / 12;
    302         const double y1 = ::floor( ( 4900.0 + year + m1 ) / 100 );
    303 
    304         const double jd = ::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2
    305             - ::floor( ( 3 * y1 ) / 4 ) + day - 32075;
     230        const double y1 = std::floor( ( 4900.0 + year + m1 ) / 100 );
     231
     232        const double jd = std::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2
     233            - std::floor( ( 3 * y1 ) / 4 ) + day - 32075;
    306234
    307235        if ( jd > maxJulianDayD )
    … …  
    311239        }
    312240
    313         return QDate::fromJulianDay( static_cast<QwtJulianDay>( jd ) );
     241        return QDate::fromJulianDay( static_cast< QwtJulianDay >( jd ) );
    314242    }
    315243    else
    … …  
    321249
    322250/*!
    323   Translate from double to QDateTime
    324 
    325   \param value Number of milliseconds since the epoch,
     251   Translate from double to QDateTime
     252
     253   \param value Number of milliseconds since the epoch,
    326254               1970-01-01T00:00:00 UTC
    327   \param timeSpec Time specification
    328   \return Datetime value
    329 
    330   \sa toDouble(), QDateTime::setMSecsSinceEpoch()
    331   \note The return datetime for Qt::OffsetFromUTC will be Qt::UTC
     255   \param timeSpec Time specification
     256   \return Datetime value
     257
     258   \sa toDouble(), QDateTime::setMSecsSinceEpoch()
     259   \note The return datetime for Qt::OffsetFromUTC will be Qt::UTC
    332260 */
    333261QDateTime QwtDate::toDateTime( double value, Qt::TimeSpec timeSpec )
    … …  
    335263    const int msecsPerDay = 86400000;
    336264
    337     const double days = static_cast<qint64>( ::floor( value / msecsPerDay ) );
     265    const double days = static_cast< qint64 >( std::floor( value / msecsPerDay ) );
    338266
    339267    const double jd = QwtDate::JulianDayForEpoch + days;
    … …  
    344272    }
    345273
    346     const QDate d = QDate::fromJulianDay( static_cast<QwtJulianDay>( jd ) );
    347 
    348     const int msecs = static_cast<int>( value - days * msecsPerDay );
     274    const QDate d = QDate::fromJulianDay( static_cast< QwtJulianDay >( jd ) );
     275
     276    const int msecs = static_cast< int >( value - days * msecsPerDay );
    349277
    350278    static const QTime timeNull( 0, 0, 0, 0 );
    … …  
    359287
    360288/*!
    361   Translate from QDateTime to double
    362 
    363   \param dateTime Datetime value
    364   \return Number of milliseconds since 1970-01-01T00:00:00 UTC has passed.
    365 
    366   \sa toDateTime(), QDateTime::toMSecsSinceEpoch()
    367   \warning For values very far below or above 1970-01-01 UTC rounding errors
     289   Translate from QDateTime to double
     290
     291   \param dateTime Datetime value
     292   \return Number of milliseconds since 1970-01-01T00:00:00 UTC has passed.
     293
     294   \sa toDateTime(), QDateTime::toMSecsSinceEpoch()
     295   \warning For values very far below or above 1970-01-01 UTC rounding errors
    368296           will happen due to the limited significance of a double.
    369297 */
    370 double QwtDate::toDouble( const QDateTime &dateTime )
     298double QwtDate::toDouble( const QDateTime& dateTime )
    371299{
    372300    const int msecsPerDay = 86400000;
    … …  
    384312
    385313/*!
    386   Ceil a datetime according the interval type
    387 
    388   \param dateTime Datetime value
    389   \param intervalType Interval type, how to ceil.
     314   Ceil a datetime according the interval type
     315
     316   \param dateTime Datetime value
     317   \param intervalType Interval type, how to ceil.
    390318                      F.e. when intervalType = QwtDate::Months, the result
    391319                      will be ceiled to the next beginning of a month
    392   \return Ceiled datetime
    393   \sa floor()
    394  */
    395 QDateTime QwtDate::ceil( const QDateTime &dateTime, IntervalType intervalType )
     320   \return Ceiled datetime
     321   \sa floor()
     322 */
     323QDateTime QwtDate::ceil( const QDateTime& dateTime, IntervalType intervalType )
    396324{
    397325    if ( dateTime.date() >= QwtDate::maxDate() )
    … …  
    485413
    486414/*!
    487   Floor a datetime according the interval type
    488 
    489   \param dateTime Datetime value
    490   \param intervalType Interval type, how to ceil.
     415   Floor a datetime according the interval type
     416
     417   \param dateTime Datetime value
     418   \param intervalType Interval type, how to ceil.
    491419                      F.e. when intervalType = QwtDate::Months,
    492420                      the result will be ceiled to the next
    493421                      beginning of a month
    494   \return Floored datetime
    495   \sa floor()
    496  */
    497 QDateTime QwtDate::floor( const QDateTime &dateTime,
     422   \return Floored datetime
     423   \sa floor()
     424 */
     425QDateTime QwtDate::floor( const QDateTime& dateTime,
    498426    IntervalType intervalType )
    499427{
    … …  
    558486
    559487/*!
    560   Minimum for the supported date range
    561 
    562   The range of valid dates depends on how QDate stores the
    563   Julian day internally.
    564 
    565   - For Qt4 it is "Tue Jan 2 -4713"
    566   - For Qt5 it is "Thu Jan 1 -2147483648"
    567 
    568   \return minimum of the date range
    569   \sa maxDate()
     488   Minimum for the supported date range
     489
     490   The range of valid dates depends on how QDate stores the
     491   Julian day internally.
     492
     493   - For Qt4 it is "Tue Jan 2 -4713"
     494   - For Qt5 it is "Thu Jan 1 -2147483648"
     495
     496   \return minimum of the date range
     497   \sa maxDate()
    570498 */
    571499QDate QwtDate::minDate()
    … …  
    579507
    580508/*!
    581   Maximum for the supported date range
    582 
    583   The range of valid dates depends on how QDate stores the
    584   Julian day internally.
    585 
    586   - For Qt4 it is "Tue Jun 3 5874898"
    587   - For Qt5 it is "Tue Dec 31 2147483647"
    588 
    589   \return maximum of the date range
    590   \sa minDate()
    591   \note The maximum differs between Qt4 and Qt5
     509   Maximum for the supported date range
     510
     511   The range of valid dates depends on how QDate stores the
     512   Julian day internally.
     513
     514   - For Qt4 it is "Tue Jun 3 5874898"
     515   - For Qt5 it is "Tue Dec 31 2147483647"
     516
     517   \return maximum of the date range
     518   \sa minDate()
     519   \note The maximum differs between Qt4 and Qt5
    592520 */
    593521QDate QwtDate::maxDate()
    … …  
    601529
    602530/*!
    603   \brief Date of the first day of the first week for a year
    604 
    605   The first day of a week depends on the current locale
    606   ( QLocale::firstDayOfWeek() ).
    607 
    608   \param year Year
    609   \param type Option how to identify the first week
    610   \return First day of week 0
    611 
    612   \sa QLocale::firstDayOfWeek(), weekNumber()
     531   \brief Date of the first day of the first week for a year
     532
     533   The first day of a week depends on the current locale
     534   ( QLocale::firstDayOfWeek() ).
     535
     536   \param year Year
     537   \param type Option how to identify the first week
     538   \return First day of week 0
     539
     540   \sa QLocale::firstDayOfWeek(), weekNumber()
    613541 */
    614542QDate QwtDate::dateOfWeek0( int year, Week0Type type )
    … …  
    628556    {
    629557        // according to ISO 8601 the first week is defined
    630         // by the first thursday.
     558        // by the first Thursday.
    631559
    632560        int d = Qt::Thursday - firstDayOfWeek;
    … …  
    642570
    643571/*!
    644   Find the week number of a date
    645 
    646   - QwtDate::FirstThursday\n
     572   Find the week number of a date
     573
     574   - QwtDate::FirstThursday\n
    647575    Corresponding to ISO 8601 ( see QDate::weekNumber() ).
    648576
    649   - QwtDate::FirstDay\n
     577   - QwtDate::FirstDay\n
    650578    Number of weeks that have begun since dateOfWeek0().
    651579
    652   \param date Date
    653   \param type Option how to identify the first week
    654 
    655   \return Week number, starting with 1
    656  */
    657 int QwtDate::weekNumber( const QDate &date, Week0Type type )
     580   \param date Date
     581   \param type Option how to identify the first week
     582
     583   \return Week number, starting with 1
     584 */
     585int QwtDate::weekNumber( const QDate& date, Week0Type type )
    658586{
    659587    int weekNo;
    … …  
    695623     0, dateTime has no offset
    696624   - Qt::OffsetFromUTC
    697      returns dateTime.utcOffset()
     625     returns dateTime.offsetFromUtc()
    698626   - Qt::LocalTime:
    699627     number of seconds from the UTC
    … …  
    705633   \return Offset in seconds
    706634 */
    707 int QwtDate::utcOffset( const QDateTime &dateTime )
     635int QwtDate::utcOffset( const QDateTime& dateTime )
    708636{
    709637    int seconds = 0;
    … …  
    717645        case Qt::OffsetFromUTC:
    718646        {
     647#if QT_VERSION >= 0x050200
     648            seconds = dateTime.offsetFromUtc();
     649#else
    719650            seconds = dateTime.utcOffset();
     651#endif
    720652            break;
    721653        }
    … …  
    731663
    732664/*!
    733   Translate a datetime into a string
    734 
    735   Beside the format expressions documented in QDateTime::toString()
    736   the following expressions are supported:
    737 
    738   - w\n
     665   Translate a datetime into a string
     666
     667   Beside the format expressions documented in QDateTime::toString()
     668   the following expressions are supported:
     669
     670   - w\n
    739671    week number: ( 1 - 53 )
    740   - ww\n
     672   - ww\n
    741673    week number with a leading zero ( 01 - 53 )
    742674
    743   As week 1 usually starts in the previous year a special rule
    744   is applied for formats, where the year is expected to match the
    745   week number - even if the date belongs to the previous year.
    746 
    747   \param dateTime Datetime value
    748   \param format Format string
    749   \param week0Type Specification of week 0
    750 
    751   \return Datetime string
    752   \sa QDateTime::toString(), weekNumber(), QwtDateScaleDraw
    753  */
    754 QString QwtDate::toString( const QDateTime &dateTime,
    755     const QString & format, Week0Type week0Type )
     675   As week 1 usually starts in the previous year a special rule
     676   is applied for formats, where the year is expected to match the
     677   week number - even if the date belongs to the previous year.
     678
     679   \param dateTime Datetime value
     680   \param format Format string
     681   \param week0Type Specification of week 0
     682
     683   \return Datetime string
     684   \sa QDateTime::toString(), weekNumber(), QwtDateScaleDraw
     685 */
     686QString QwtDate::toString( const QDateTime& dateTime,
     687    const QString& format, Week0Type week0Type )
    756688{
    757689    QString fmt = format;
    … …  
    761693    }
    762694
    763     return dateTime.toString( fmt );
    764 }
     695    return QLocale().toString( dateTime, fmt );
     696}
Note: See TracChangeset for help on using the changeset viewer.