Qtopia library API Documentation

timestring.h

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 // return a string with the time based on whether or not you want
00027 // you want it in 12 hour form.   if ampm is true, then return
00028 // it in 12 hour (am/pm) form otherwise return it in 24 hour form
00029 // in theory Qt 3,0 handles this better (hopefully obsoleteing this)
00030 class DateFormat 
00031 {
00032 public:
00033     // date format type 001,010,100 = day month year
00034     enum Order {
00035     DayMonthYear = 0x0111, // 0x001 + 0x010(0x2 << 3) + 0x100(0x4 << 3)
00036     MonthDayYear = 0x010A,
00037     YearMonthDay = 0x0054
00038     };
00039 
00040     DateFormat(QChar s = '/', Order so = MonthDayYear) : _shortOrder(so),
00041         _longOrder(so), _shortSeparator(s) { }
00042     DateFormat(QChar s, Order so, Order lo) :  _shortOrder(so),
00043         _longOrder(lo), _shortSeparator(s) { }
00044     DateFormat(const DateFormat &o) : _shortOrder(o._shortOrder),
00045         _longOrder(o._longOrder), _shortSeparator(o._shortSeparator) { }
00046 
00047     bool operator==(const DateFormat &o)
00048     {
00049     if (o._shortOrder == _shortOrder && o._longOrder == _longOrder &&
00050         o._shortSeparator == _shortSeparator)
00051         return TRUE;
00052     return FALSE;
00053     }
00054 
00055     // verbosity specifiers
00056     enum Verbosity {
00057     shortNumber = 0x01, // default
00058     longNumber  = 0x02,
00059 
00060     padNumber = 0x04,
00061 
00062     shortWord = 0x08, // default
00063     longWord = 0x10,
00064 
00065     showWeekDay = 0x20
00066     };
00067 
00068     QString toNumberString() const; // the M/D/Y string.
00069     QString toWordString() const; // the Month day, year string.
00070 
00071     QString numberDate(const QDate &d, int v = 0) const;
00072     QString wordDate(const QDate &d, int v = 0) const;
00073 
00074 #ifndef QT_NO_DATASTREAM
00075     void load(QDataStream&);
00076     void save(QDataStream&) const;
00077 #endif
00078 
00079     QChar separator() const { return _shortSeparator; };
00080     Order shortOrder() const { return _shortOrder; };
00081     Order longOrder() const { return _longOrder; };
00082 
00083 private:
00084     Order _shortOrder;
00085     Order _longOrder;
00086     QChar _shortSeparator;
00087 };
00088 
00089 #ifndef QT_NO_DATASTREAM
00090 QDataStream &operator<<(QDataStream &s, const DateFormat&df);
00091 QDataStream &operator>>(QDataStream &s, DateFormat&df);
00092 #endif
00093 
00094 class TimeString
00095 {
00096 public:
00097 
00098     //enum DateFormat { MonthDayYear, DayMonthYear, ISO8601, 
00099               //YearMonthDay = ISO8601 };
00100 
00101 
00102     static QString shortDate( const QDate &d ) 
00103     { return shortDate( d, currentDateFormat() ); }
00104     static QString dateString( const QDate &d )
00105     { return dateString( d, currentDateFormat() ); }
00106     static QString longDateString( const QDate &d )
00107     { return longDateString( d, currentDateFormat() ); }
00108     static QString dateString( const QDateTime &dt, bool ampm, bool seconds )
00109     { return dateString( dt, ampm, seconds, currentDateFormat() ); }
00110 
00111     static QString dateString( const QDateTime &t, bool ampm = false );
00112     static QString timeString( const QTime &t, bool ampm, bool seconds );
00113     static QString timeString( const QTime &t, bool ampm = false );
00114     static QString shortTime( bool ampm, bool seconds );
00115     static QString shortTime( bool ampm = false );
00116 
00117     static QString numberDateString( const QDate &d, DateFormat );
00118     static QString numberDateString( const QDate &d )
00119     { return numberDateString( d, currentDateFormat() ); }
00120     static QString longNumberDateString( const QDate &d, DateFormat );
00121     static QString longNumberDateString( const QDate &d )
00122     { return longNumberDateString( d, currentDateFormat() ); }
00123 
00124     static QString shortDate( const QDate &, DateFormat );
00125     static QString dateString( const QDate &, DateFormat  );
00126     static QString longDateString( const QDate &, DateFormat );
00127 
00128     static DateFormat currentDateFormat();
00129 
00130 private:
00131     static QString dateString( const QDateTime &t, bool ampm, bool seconds, DateFormat );
00132     
00133 
00134 };
00135 
00136 #endif
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:08 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001