Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

timestring.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #ifndef _TIMESTRING_H_
00022 #define _TIMESTRING_H_
00023 #include <qdatetime.h>
00024 #include <qstring.h>
00025 
00026 #if (QT_VERSION-0 >= 0x030000)
00027 #define DateFormat QPEDateFormat
00028 #endif
00029 
00030 // return a string with the time based on whether or not you want
00031 // you want it in 12 hour form.   if ampm is true, then return
00032 // it in 12 hour (am/pm) form otherwise return it in 24 hour form
00033 // in theory Qt 3,0 handles this better (hopefully obsoleteing this)
00034 class DateFormat
00035 {
00036 public:
00037     // date format type 001,010,100 = day month year
00038     enum Order {
00039         DayMonthYear = 0x0111, // 0x001 + 0x010(0x2 << 3) + 0x100(0x4 << 3)
00040         MonthDayYear = 0x010A,
00041         YearMonthDay = 0x0054
00042     };
00043 
00044     DateFormat(QChar s = '/', Order so = MonthDayYear) : _shortOrder(so),
00045         _longOrder(so), _shortSeparator(s) { }
00046     DateFormat(QChar s, Order so, Order lo) :  _shortOrder(so),
00047         _longOrder(lo), _shortSeparator(s) { }
00048     DateFormat(const DateFormat &o) : _shortOrder(o._shortOrder),
00049         _longOrder(o._longOrder), _shortSeparator(o._shortSeparator) { }
00050 
00051     bool operator==(const DateFormat &o)
00052     {
00053         if (o._shortOrder == _shortOrder && o._longOrder == _longOrder &&
00054                 o._shortSeparator == _shortSeparator)
00055             return TRUE;
00056         return FALSE;
00057     }
00058 
00059     // verbosity specifiers
00060     enum Verbosity {
00061         shortNumber = 0x01, // default
00062         longNumber  = 0x02,
00063 
00064         padNumber = 0x04,
00065 
00066         shortWord = 0x08, // default
00067         longWord = 0x10,
00068 
00069         showWeekDay = 0x20
00070     };
00071 
00072     QString toNumberString() const; // the M/D/Y string.
00073     QString toWordString() const; // the Month day, year string.
00074 
00075     QString numberDate(const QDate &d, int v = 0) const;
00076     QString wordDate(const QDate &d, int v = 0) const;
00077 
00078 #ifndef QT_NO_DATASTREAM
00079     void load(QDataStream&);
00080     void save(QDataStream&) const;
00081 #endif
00082 
00083     QChar separator() const { return _shortSeparator; };
00084     Order shortOrder() const { return _shortOrder; };
00085     Order longOrder() const { return _longOrder; };
00086 
00087 private:
00088     Order _shortOrder;
00089     Order _longOrder;
00090     QChar _shortSeparator;
00091 };
00092 
00093 #ifndef QT_NO_DATASTREAM
00094 QDataStream &operator<<(QDataStream &s, const DateFormat&df);
00095 QDataStream &operator>>(QDataStream &s, DateFormat&df);
00096 #endif
00097 
00098 class TimeString
00099 {
00100 public:
00101 
00102     //enum DateFormat { MonthDayYear, DayMonthYear, ISO8601,
00103                       //YearMonthDay = ISO8601 };
00104 
00109     static QString shortDate( const QDate &d )
00110     { return shortDate( d, currentDateFormat() ); }
00111     static QString dateString( const QDate &d )
00112     { return dateString( d, currentDateFormat() ); }
00113     static QString longDateString( const QDate &d )
00114     { return longDateString( d, currentDateFormat() ); }
00116     static QString dateString( const QDateTime &dt, bool ampm, bool seconds )
00117     { return dateString( dt, ampm, seconds, currentDateFormat() ); }
00118 
00119 
00124     static QString dateString( const QDateTime &t, bool ampm = false );
00125     static QString timeString( const QTime &t, bool ampm, bool seconds );
00126     static QString timeString( const QTime &t, bool ampm = false );
00127     static QString shortTime( bool ampm, bool seconds );
00128     static QString shortTime( bool ampm = false );
00130 
00131     static QString numberDateString( const QDate &d, DateFormat );
00132     static QString numberDateString( const QDate &d )
00133     { return numberDateString( d, currentDateFormat() ); }
00134     static QString longNumberDateString( const QDate &d, DateFormat );
00135     static QString longNumberDateString( const QDate &d )
00136     { return longNumberDateString( d, currentDateFormat() ); }
00137 
00138     static QString shortDate( const QDate &, DateFormat );
00139     static QString dateString( const QDate &, DateFormat  );
00140     static QString longDateString( const QDate &, DateFormat );
00141 
00142     static DateFormat currentDateFormat();
00143 
00144 private:
00145     static QString dateString( const QDateTime &t, bool ampm, bool seconds, DateFormat );
00146 
00147 
00148 };
00149 
00150 #endif

Generated on Sat Nov 5 16:16:41 2005 for OPIE by  doxygen 1.4.2