Qt Virtual Chart Table (QVCT)
CUnitDate.hpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Qt Virtual Chart Table (QVCT)
5  * Copyright (C) 2012 Cedric Dufour <http://cedric.dufour.name>
6  * Author: Cedric Dufour <http://cedric.dufour.name>
7  *
8  * The Qt Virtual Chart Table (QVCT) is free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Qt Virtual Chart Table (QVCT) is distributed in the hope
13  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * See the GNU General Public License for more details.
17  */
18 
19 #ifndef QVCT_CUNITDATE_HPP
20 #define QVCT_CUNITDATE_HPP
21 
22 // QT
23 #include <QMap>
24 #include <QString>
25 
26 // QVCT
27 #include "units/CUnitTimeZone.hpp"
28 class CUnitDateSymbols; // see below
29 class CUnitDateCodes; // see below
30 
31 
33 
38 class CUnitDate
39 {
40 
41  //------------------------------------------------------------------------------
42  // CONSTANTS / STATIC
43  //------------------------------------------------------------------------------
44 
45 public:
47  enum EUnit {
48  YMD,
49  DMY,
50  MDY,
51  UNDEFINED
52  };
53 
54 private:
59 
60 public:
62  static const QMap<EUnit,QString> &symbols();
64  static QString toSymbol( EUnit _eUnit );
66  static EUnit fromSymbol( const QString& _rqsSymbol );
68  static const QMap<EUnit,QString> &codes();
70  static QString toCode( EUnit _eUnit );
72  static EUnit fromCode( const QString& _rqsCode );
74  static QString toString( double _fdValue, CUnitTimeZone::EUnit _eUnitTimeZone, EUnit _eUnit );
76  static QString toString( double _fdValue, bool _bAlternateTimeZone = false );
78 
87  static double fromString( const QString& _rqString, CUnitTimeZone::EUnit _eUnitTimeZone, bool* _pbOK = 0 );
89  static double fromString( const QString& _rqString, bool* _pbOK = 0 );
90 
91 };
92 
95 {
96  friend class CUnitDate;
97 
98  //------------------------------------------------------------------------------
99  // CONSTRUCTORS / DESTRUCTOR
100  //------------------------------------------------------------------------------
101 
102 private:
104  {
105  qMapSymbols.insert( CUnitDate::YMD, "yyyy-mm-dd" );
106  qMapSymbols.insert( CUnitDate::DMY, "dd.mm.yyyy" );
107  qMapSymbols.insert( CUnitDate::MDY, "mm,dd,yyyy" );
108  };
109  QMap<CUnitDate::EUnit,QString> qMapSymbols;
110 };
111 
114 {
115  friend class CUnitDate;
116 
117  //------------------------------------------------------------------------------
118  // CONSTRUCTORS / DESTRUCTOR
119  //------------------------------------------------------------------------------
120 
121 private:
123  {
124  qMapCodes.insert( CUnitDate::YMD, "ymd" );
125  qMapCodes.insert( CUnitDate::DMY, "dmy" );
126  qMapCodes.insert( CUnitDate::MDY, "mdy" );
127  };
128  QMap<CUnitDate::EUnit,QString> qMapCodes;
129 };
130 
131 #endif // QVCT_CUNITDATE_HPP
Container class for supported machine-friendly format/unit codes.
Definition: CUnitDate.hpp:114
QMap< CUnitDate::EUnit, QString > qMapCodes
Definition: CUnitDate.hpp:127
Container class for supported human-readable format/unit symbols.
Definition: CUnitDate.hpp:95
QMap< CUnitDate::EUnit, QString > qMapSymbols
Definition: CUnitDate.hpp:108
Date unit (YMD, DMY, MDY) rendering/parsing class.
Definition: CUnitDate.hpp:39
static EUnit fromCode(const QString &_rqsCode)
Returns the format/unit ID corresponding to the given machine-friendly code.
Definition: CUnitDate.cpp:66
static const CUnitDateCodes oUnitDateCodes
Container for supported machine-friendly format/unit codes.
Definition: CUnitDate.hpp:58
static const QMap< EUnit, QString > & symbols()
Returns the list of supported human-readable format/unit symbols.
Definition: CUnitDate.cpp:41
static const CUnitDateSymbols oUnitDateSymbols
Container for supported human-readable format/unit symbols.
Definition: CUnitDate.hpp:56
static const QMap< EUnit, QString > & codes()
Returns the list of supported machine-friendly format/unit codes.
Definition: CUnitDate.cpp:56
static QString toString(double _fdValue, CUnitTimeZone::EUnit _eUnitTimeZone, EUnit _eUnit)
Returns the formatted represention of the given value, using the specified format/unit and decimal pr...
Definition: CUnitDate.cpp:71
static double fromString(const QString &_rqString, CUnitTimeZone::EUnit _eUnitTimeZone, bool *_pbOK=0)
Returns the numeric value corresponding (parsed) from the string.
Definition: CUnitDate.cpp:99
EUnit
Format/unit ID.
Definition: CUnitDate.hpp:47
@ MDY
MM-DD-YYYY.
Definition: CUnitDate.hpp:50
@ UNDEFINED
undefined format/unit
Definition: CUnitDate.hpp:51
@ YMD
YYYY-MM-DD.
Definition: CUnitDate.hpp:48
@ DMY
DD-MM-YYYY.
Definition: CUnitDate.hpp:49
static QString toSymbol(EUnit _eUnit)
Returns the human-readable symbol corresponding to the given format/unit ID.
Definition: CUnitDate.cpp:46
static EUnit fromSymbol(const QString &_rqsSymbol)
Returns the format/unit ID corresponding to the given human-readable symbol.
Definition: CUnitDate.cpp:51
static QString toCode(EUnit _eUnit)
Returns the machine-friendly code corresponding to the given format/unit ID.
Definition: CUnitDate.cpp:61
EUnit
Format/unit ID.