NCBI C++ ToolKit
Date.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: Date.hpp 62599 2014-04-22 20:39:51Z ucko $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Aaron Ucko, NCBI
27  *
28  * File Description:
29  * Useful member functions for dates: comparison and formatting
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using specifications from the ASN data definition file
34  * 'general.asn'.
35  */
36 
37 #ifndef OBJECTS_GENERAL_DATE_HPP
38 #define OBJECTS_GENERAL_DATE_HPP
39 
40 
41 // generated includes
43 
44 #include <corelib/ncbitime.hpp>
45 
46 // generated classes
47 
49 
50 BEGIN_objects_SCOPE // namespace ncbi::objects::
51 
53 {
55 public:
56  /// for conversion from CTime
57  enum EPrecision {
59  ePrecision_second
60  };
61 
62  // constructors; the latter two make Date-stds
63  CDate(void);
64  CDate(const CTime& time, EPrecision prec = ePrecision_second);
65  explicit CDate(time_t time, EPrecision prec = ePrecision_second);
66  // destructor
67  ~CDate(void);
68 
69  void SetToTime(const CTime& time, EPrecision prec = ePrecision_second);
70  CTime AsCTime (CTime::ETimeZone tz = CTime::eLocal) const;
71 
72  /// How *this relates to another date.
73  enum ECompare {
74  eCompare_before = -1, ///< *this comes first.
75  eCompare_same, ///< They're equivalent.
76  eCompare_after, ///< *this comes second.
77  eCompare_unknown ///< Comparison is impossible.
78  };
79  ECompare Compare(const CDate& date) const;
80 
81  /// Append a standardized string representation of the date to the label.
82  ///
83  /// Dates internally represented as strings necessarily appear as is.
84  /// Structured dates with known months and days normally appear in a
85  /// mm-dd-yyyy format; however, if either field is missing, or
86  /// year_only is true, this method will yield only the year.
87  void GetDate(string* label, bool year_only = false) const;
88 
89  /// Append a custom string representation of the date to the label.
90  ///
91  /// \p format controls the treatment of Date-std. (Strings
92  /// necessarily remain as is.) Specifically,
93  /// \verbatim
94  /// %Y -> year
95  /// %M -> month as number
96  /// %N -> month as (English) word
97  /// %D -> day
98  /// %S -> season
99  /// %h -> hour
100  /// %m -> minute
101  /// %s -> second
102  /// \endverbatim
103  /// Each of the above can contain a number immediately following the
104  /// percent sign, indicating the number of characters to yield.
105  ///
106  /// In addition, there are special directives to deal with optional
107  /// elements: %{ ... %} (which may be nested) may be used to
108  /// delimit subsequences that should vanish altogether if optional
109  /// elements they contain are missing, and %| may be used to
110  /// designate fallbacks. (For instance, the above interface
111  /// defaults to a format of "%{%2M-%2D-%}%Y", and one might format
112  /// dates for GenBank with "%{%{%2D%|01%}-%3N%|01-JAN%}-%Y" if one
113  /// wanted to fudge legal values if necessary.)
114  ///
115  /// Finally, %% -> %.
116  void GetDate(string* label, const string& format) const;
117  void GetDate(string* label, const char* format) const;
118 
119 private:
120  // Prohibit copy constructor and assignment operator
121  CDate(const CDate& value);
123 
124 };
125 
126 
127 
128 /////////////////// CDate inline methods
129 
130 // constructors
131 inline
133 {
134 }
135 
136 inline CDate::CDate(const CTime& time, CDate::EPrecision prec)
137 {
138  SetToTime(time, prec);
139 }
140 
141 inline CDate::CDate(time_t time, CDate::EPrecision prec)
142 {
143  SetToTime(CTime(time), prec);
144 }
145 
146 
147 // old version of GetDate
148 inline
149 void CDate::GetDate(string* label, bool year_only) const
150 {
151  GetDate(label, year_only ? "%Y" : "%{%2M-%2D-%}%Y");
152 }
153 
154 
155 // Make sure that stupid compilers don't try to cast char* to bool....
156 inline
157 void CDate::GetDate(string* label, const char* format) const
158 {
159  GetDate(label, string(format));
160 }
161 
162 
163 /////////////////// end of CDate inline methods
164 
165 
166 END_objects_SCOPE // namespace ncbi::objects::
167 
169 
170 #endif // OBJECTS_GENERAL_DATE_HPP
171 /* Original file checksum: lines: 90, chars: 2320, CRC32: 5affaceb */
Data storage class.
StringStore is really a VisibleString.
Definition: Date_.hpp:113
Definition: Date.hpp:53
CDate_Base Tparent
Definition: Date.hpp:54
CDate(void)
Definition: Date.hpp:132
CDate & operator=(const CDate &value)
CDate(const CDate &value)
void GetDate(string *label, bool year_only=false) const
Append a standardized string representation of the date to the label.
Definition: Date.hpp:149
void SetToTime(const CTime &time, EPrecision prec=ePrecision_second)
Definition: Date.cpp:57
EPrecision
for conversion from CTime
Definition: Date.hpp:57
@ ePrecision_day
Definition: Date.hpp:58
ECompare
How *this relates to another date.
Definition: Date.hpp:73
@ eCompare_same
They're equivalent.
Definition: Date.hpp:75
@ eCompare_after
*this comes second.
Definition: Date.hpp:76
CTime –.
Definition: ncbitime.hpp:296
char value[7]
Definition: config.c:431
sequence::ECompare Compare(const CSeq_loc &loc1, const CSeq_loc &loc2, CScope *scope)
Returns the sequence::ECompare containment relationship between CSeq_locs.
ECompare
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
ETimeZone
Which initial value to use for timezone.
Definition: ncbitime.hpp:305
@ eLocal
Local time.
Definition: ncbitime.hpp:306
#define NCBI_GENERAL_EXPORT
Definition: ncbi_export.h:512
static const char label[]
Defines: CTimeFormat - storage class for time format.
static Format format
Definition: njn_ioutil.cpp:53
Modified on Thu Mar 28 17:11:35 2024 by modify_doxy.py rev. 669887