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

Go to the SVN repository for this file.

1 /* $Id: Date.cpp 33815 2007-05-04 17:18:18Z kazimird $
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 // standard includes
38 
39 // generated includes
40 #include <ncbi_pch.hpp>
41 #include <objects/general/Date.hpp>
42 
44 
45 // generated classes
46 
48 
49 BEGIN_objects_SCOPE // namespace ncbi::objects::
50 
51 // destructor
53 {
54 }
55 
56 
57 void CDate::SetToTime(const CTime& time, CDate::EPrecision prec)
58 {
59  switch (Which()) {
60  case e_not_set:
61  case e_Std:
62  SetStd().SetToTime(time, prec);
63  break;
64  case e_Str:
65  SetStr(time.AsString());
66  break;
67  }
68 }
69 
71 {
72  switch (Which()) {
73  case e_Std:
74  return GetStd().AsCTime(tz);
75  case e_Str:
76  return CTime(GetStr()); // attempt to parse
77  default:
78  return CTime(CTime::eEmpty);
79  }
80 }
81 
82 
84 {
85  if (IsStd() && date.IsStd() ) {
86  return GetStd().Compare(date.GetStd());
87  } else if (IsStr() && date.IsStr() && GetStr() == date.GetStr()) {
88  return eCompare_same;
89  } else {
90  return eCompare_unknown;
91  }
92 }
93 
94 void CDate::GetDate(string* label, const string& format) const
95 {
96  // Ensure that date exists
97  if (!label) {
98  return;
99  }
100 
101  switch (Which()) {
102  case e_Str:
103  *label += GetStr();
104  return;
105  case e_Std:
107  return;
108  default:
109  return;
110  }
111 }
112 
113 
114 
115 END_objects_SCOPE // namespace ncbi::objects::
116 
118 
119 /* Original file checksum: lines: 61, chars: 1873, CRC32: d1b93689 */
CDate::ECompare Compare(const CDate_std &date) const
Indicate how *this relates to another date.
Definition: Date_std.cpp:91
void SetToTime(const CTime &time, CDate::EPrecision prec=CDate::ePrecision_second)
Definition: Date_std.cpp:59
CTime AsCTime(CTime::ETimeZone tz=CTime::eLocal) const
Definition: Date_std.cpp:78
void GetDate(string *label, const string &format) const
Append a custom string representation of the date to the label.
Definition: Date_std.cpp:159
Definition: Date.hpp:53
ECompare Compare(const CDate &date) const
Definition: Date.cpp:83
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
CTime AsCTime(CTime::ETimeZone tz=CTime::eLocal) const
Definition: Date.cpp:70
EPrecision
for conversion from CTime
Definition: Date.hpp:57
~CDate(void)
Definition: Date.cpp:52
ECompare
How *this relates to another date.
Definition: Date.hpp:73
@ eCompare_same
They're equivalent.
Definition: Date.hpp:75
@ eCompare_unknown
Comparison is impossible.
Definition: Date.hpp:77
CTime –.
Definition: ncbitime.hpp:296
#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
string AsString(const CTimeFormat &format=kEmptyStr, TSeconds out_tz=eCurrentTimeZone) const
Transform time to string.
Definition: ncbitime.cpp:1512
@ eEmpty
Use "empty" time.
Definition: ncbitime.hpp:301
static const char label[]
bool IsStd(void) const
Check if variant Std is selected.
Definition: Date_.hpp:320
TStd & SetStd(void)
Select the variant.
Definition: Date_.cpp:115
const TStr & GetStr(void) const
Get the variant data.
Definition: Date_.hpp:306
E_Choice Which(void) const
Which variant is currently selected.
Definition: Date_.hpp:271
TStr & SetStr(void)
Select the variant.
Definition: Date_.hpp:313
const TStd & GetStd(void) const
Get the variant data.
Definition: Date_.cpp:109
bool IsStr(void) const
Check if variant Str is selected.
Definition: Date_.hpp:300
@ e_not_set
No variant selected.
Definition: Date_.hpp:127
@ e_Str
for those unparsed dates
Definition: Date_.hpp:128
@ e_Std
use this if you can
Definition: Date_.hpp:129
static Format format
Definition: njn_ioutil.cpp:53
Modified on Sun May 19 04:45:37 2024 by modify_doxy.py rev. 669887