Qt Virtual Chart Table (QVCT)
CUnitTime.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_CUNITTIME_HPP
20 #define QVCT_CUNITTIME_HPP
21 
22 // QT
23 #include <QMap>
24 #include <QString>
25 
26 // QVCT
27 #include "units/CUnitTimeZone.hpp"
28 class CUnitTimeSymbols; // see below
29 class CUnitTimeCodes; // see below
30 
31 
33 
38 class CUnitTime
39 {
40 
41  //------------------------------------------------------------------------------
42  // CONSTANTS / STATIC
43  //------------------------------------------------------------------------------
44 
45 public:
47  enum EUnit {
48  HMS,
49  HM,
50  UNDEFINED
51  };
52 
53 private:
58 
59 public:
61  static const QMap<EUnit,QString> &symbols();
63  static QString toSymbol( EUnit _eUnit );
65  static EUnit fromSymbol( const QString& _rqsSymbol );
67  static const QMap<EUnit,QString> &codes();
69  static QString toCode( EUnit _eUnit );
71  static EUnit fromCode( const QString& _rqsCode );
73  static double toValue( double _fdValue, CUnitTimeZone::EUnit _eUnitTimeZone );
75  static QString toString( double _fdValue, CUnitTimeZone::EUnit _eUnitTimeZone, EUnit _eUnit, int _iPrecision = 0 );
77  static QString toString( double _fdValue, bool _bAlternateTimeZone = false );
79 
89  static double fromString( const QString& _rqString, double _fdDate, CUnitTimeZone::EUnit _eUnitTimeZone, bool* _pbOK = 0 );
91  static double fromString( const QString& _rqString, double _fdDate, bool* _pbOK = 0 );
92 
93 };
94 
97 {
98  friend class CUnitTime;
99 
100  //------------------------------------------------------------------------------
101  // CONSTRUCTORS / DESTRUCTOR
102  //------------------------------------------------------------------------------
103 
104 private:
106  {
107  qMapSymbols.insert( CUnitTime::HMS, "hh:mm:ss" );
108  qMapSymbols.insert( CUnitTime::HM, "hh:mm" );
109  };
110  QMap<CUnitTime::EUnit,QString> qMapSymbols;
111 };
112 
115 {
116  friend class CUnitTime;
117 
118  //------------------------------------------------------------------------------
119  // CONSTRUCTORS / DESTRUCTOR
120  //------------------------------------------------------------------------------
121 
122 private:
124  {
125  qMapCodes.insert( CUnitTime::HMS, "hms" );
126  qMapCodes.insert( CUnitTime::HM, "hm" );
127  };
128  QMap<CUnitTime::EUnit,QString> qMapCodes;
129 };
130 
131 #endif // QVCT_CUNITTIME_HPP
Container class for supported machine-friendly format/unit codes.
Definition: CUnitTime.hpp:115
QMap< CUnitTime::EUnit, QString > qMapCodes
Definition: CUnitTime.hpp:127
Container class for supported human-readable format/unit symbols.
Definition: CUnitTime.hpp:97
QMap< CUnitTime::EUnit, QString > qMapSymbols
Definition: CUnitTime.hpp:109
EUnit
Format/unit ID.
Time unit (HMS, HM) rendering/parsing class.
Definition: CUnitTime.hpp:39
static double fromString(const QString &_rqString, double _fdDate, CUnitTimeZone::EUnit _eUnitTimeZone, bool *_pbOK=0)
Returns the numeric value corresponding (parsed) from the string.
Definition: CUnitTime.cpp:122
static QString toString(double _fdValue, CUnitTimeZone::EUnit _eUnitTimeZone, EUnit _eUnit, int _iPrecision=0)
Returns the formatted represention of the given value, using the specified format/unit and decimal pr...
Definition: CUnitTime.cpp:79
static const CUnitTimeCodes oUnitTimeCodes
Container for supported machine-friendly format/unit codes.
Definition: CUnitTime.hpp:57
EUnit
Format/unit ID.
Definition: CUnitTime.hpp:47
@ UNDEFINED
undefined format/unit
Definition: CUnitTime.hpp:50
@ HM
HH:MM.
Definition: CUnitTime.hpp:49
@ HMS
HH:MM:SS.
Definition: CUnitTime.hpp:48
static EUnit fromSymbol(const QString &_rqsSymbol)
Returns the format/unit ID corresponding to the given human-readable symbol.
Definition: CUnitTime.cpp:51
static const CUnitTimeSymbols oUnitTimeSymbols
Container for supported human-readable format/unit symbols.
Definition: CUnitTime.hpp:55
static const QMap< EUnit, QString > & codes()
Returns the list of supported machine-friendly format/unit codes.
Definition: CUnitTime.cpp:56
static QString toSymbol(EUnit _eUnit)
Returns the human-readable symbol corresponding to the given format/unit ID.
Definition: CUnitTime.cpp:46
static const QMap< EUnit, QString > & symbols()
Returns the list of supported human-readable format/unit symbols.
Definition: CUnitTime.cpp:41
static EUnit fromCode(const QString &_rqsCode)
Returns the format/unit ID corresponding to the given machine-friendly code.
Definition: CUnitTime.cpp:66
static QString toCode(EUnit _eUnit)
Returns the machine-friendly code corresponding to the given format/unit ID.
Definition: CUnitTime.cpp:61
static double toValue(double _fdValue, CUnitTimeZone::EUnit _eUnitTimeZone)
Returns the converted value, using the specified format/unit.
Definition: CUnitTime.cpp:71