DateTime.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 
11 
12 #include "WString.h"
13 
15 
18 
19 //=======================================================================================
27 //=======================================================================================
28 struct DateTime
29 {
30 public:
31  //=======================================================================================
34  // @bsiclass Bentley Systems
35  //=======================================================================================
36  enum class Kind
37  {
40  Unspecified = 0,
41 
43  Utc = 1,
44 
46  Local = 2
47  };
48 
49  //=======================================================================================
51  // @bsiclass Bentley Systems
52  //=======================================================================================
53  enum class Component
54  {
56  Date = 0,
57 
59  DateAndTime = 1,
60  };
61 
62  //=======================================================================================
64  // @bsiclass Bentley Systems
65  //=======================================================================================
66  enum class DayOfWeek
67  {
68  Sunday = 0,
69  Monday = 1,
70  Tuesday = 2,
71  Wednesday = 3,
72  Thursday = 4,
73  Friday = 5,
74  Saturday = 6
75  };
76 
77  //=======================================================================================
80  // @bsiclass Bentley Systems
81  //=======================================================================================
82  enum class CompareResult
83  {
84  EarlierThan,
85  Equals,
86  LaterThan,
87  Error
88  };
89 
90  //=======================================================================================
92  // @bsiclass Bentley Systems
93  //=======================================================================================
94  struct Info
95  {
96  private:
97  Kind m_kind;
98  Component m_component;
99 
100  public:
101  //***** Construction ******
102 
105 
109  BENTLEYDLL_EXPORT Info (Kind kind, Component component);
110 
114  BENTLEYDLL_EXPORT bool operator== (Info const& rhs) const;
115 
119  BENTLEYDLL_EXPORT bool operator!= (Info const& rhs) const;
120 
123  BENTLEYDLL_EXPORT Kind GetKind () const;
124 
127  BENTLEYDLL_EXPORT Component GetComponent () const;
128 
132  BENTLEYDLL_EXPORT static WString KindToString (DateTime::Kind kind);
133 
137  BENTLEYDLL_EXPORT static WString ComponentToString (DateTime::Component component);
138  };
139 
140 private:
141  Info m_info;
142  Int16 m_year;
143  UInt8 m_month;
144  UInt8 m_day;
145  UInt8 m_hour;
146  UInt8 m_minute;
147  UInt8 m_second;
148  UInt32 m_hectoNanosecond;
149 
150 public:
151  //***** Construction ******
152 
156 
164  BENTLEYDLL_EXPORT DateTime (Int16 year, UInt8 month, UInt8 day);
165 
175  BENTLEYDLL_EXPORT DateTime (Kind kind, Int16 year, UInt8 month, UInt8 day, UInt8 hour, UInt8 minute, UInt8 second = 0, UInt32 hectoNanosecond = 0);
176 
180  BENTLEYDLL_EXPORT bool IsValid () const;
181 
182 
186  bool operator== (DateTime const& rhs) const { return Equals (rhs, false); }
187 
191  bool operator!= (DateTime const& rhs) const { return !(*this == rhs); }
192 
197  BENTLEYDLL_EXPORT bool Equals (DateTime const& rhs, bool ignoreDateTimeInfo = false) const;
198 
207  BENTLEYDLL_EXPORT static CompareResult Compare (DateTime const& lhs, DateTime const& rhs);
208 
211 
214  BENTLEYDLL_EXPORT static DateTime GetCurrentTime ();
215 
218  BENTLEYDLL_EXPORT static DateTime GetCurrentTimeUtc ();
219 
221 
233 
239  BENTLEYDLL_EXPORT BentleyStatus ToJulianDay (UInt64& julianDayInHns) const;
240 
246  BENTLEYDLL_EXPORT BentleyStatus ToJulianDay (double& julianDay) const;
247 
254  BENTLEYDLL_EXPORT static BentleyStatus FromJulianDay (DateTime& dateTime, UInt64 julianDayInHns, Info const& targetInfo);
255 
262  BENTLEYDLL_EXPORT static BentleyStatus FromJulianDay (DateTime& dateTime, double julianDay, Info const& targetInfo);
263 
265 
268 
273  BENTLEYDLL_EXPORT BentleyStatus ToUtc (DateTime& utcDateTime) const;
274 
279  BENTLEYDLL_EXPORT BentleyStatus ToLocalTime (DateTime& localDateTime) const;
280 
291  BENTLEYDLL_EXPORT BentleyStatus ToUnixMilliseconds (Int64& unixMilliseconds) const;
292 
298  BENTLEYDLL_EXPORT static BentleyStatus FromUnixMilliseconds (DateTime& dateTime, UInt64 unixMilliseconds);
299 
303  BENTLEYDLL_EXPORT static Int64 JulianDayToUnixMilliseconds (UInt64 julianDayInHectoNanoseconds);
304 
308  BENTLEYDLL_EXPORT static UInt64 UnixMillisecondsToJulianDay (UInt64 unixMilliseconds);
309 
316  BENTLEYDLL_EXPORT BentleyStatus ToCommonEraTicks (Int64& commonEraTicks) const;
317 
325  BENTLEYDLL_EXPORT static BentleyStatus FromCommonEraTicks (DateTime& dateTime, Int64 commonEraTicks, Info const& targetInfo);
326 
331  BENTLEYDLL_EXPORT static Int64 JulianDayToCommonEraTicks (UInt64 julianDayInHectoNanoseconds);
332 
337  BENTLEYDLL_EXPORT static UInt64 CommonEraTicksToJulianDay (Int64 commonEraTicks);
338 
339 
342 
348  BENTLEYDLL_EXPORT Utf8String ToUtf8String () const;
349 
355  WString ToString () const
356  {
357  return WString (ToUtf8String ().c_str (), BentleyCharEncoding::Utf8);
358  }
359 
368  BENTLEYDLL_EXPORT static BentleyStatus FromString (DateTime& dateTime, Utf8CP dateTimeIso8601);
369 
378  BENTLEYDLL_EXPORT static BentleyStatus FromString (DateTime& dateTime, WCharCP dateTimeIso8601);
379 
382 
385  BENTLEYDLL_EXPORT Info const& GetInfo () const;
386 
387 
390  BENTLEYDLL_EXPORT Int16 GetYear () const;
391 
394  BENTLEYDLL_EXPORT UInt8 GetMonth () const;
395 
398  BENTLEYDLL_EXPORT UInt8 GetDay () const;
399 
402  BENTLEYDLL_EXPORT UInt8 GetHour () const;
403 
406  BENTLEYDLL_EXPORT UInt8 GetMinute () const;
407 
410  BENTLEYDLL_EXPORT UInt8 GetSecond () const;
411 
415  BENTLEYDLL_EXPORT UInt16 GetMillisecond () const;
416 
420  BENTLEYDLL_EXPORT UInt32 GetHectoNanosecond () const;
421 
425  BENTLEYDLL_EXPORT DayOfWeek GetDayOfWeek () const;
426 
429  BENTLEYDLL_EXPORT UInt16 GetDayOfYear () const;
430 
433  BENTLEYDLL_EXPORT static bool IsLeapYear (UInt16 year);
434 
436  BENTLEYDLL_EXPORT BentleyStatus ComputeOffsetToUtcInHns(Int64& offset) const;
438 
439  };
440 
441 //Convenience typedefs for the DateTime type
443 typedef DateTime const& DateTimeCR;
445 typedef DateTime const* DateTimeCP;
446 
448 
Contains a UTF-8 encoded string.
Definition: WString.h:275
#define BENTLEYDLL_EXPORT
Definition: Bentley.h:249
DateTime * DateTimeP
Definition: DateTime.h:444
DateTime const * DateTimeCP
Definition: DateTime.h:445
uint16_t UInt16
Definition: Bentley.r.h:118
WString ToString() const
Converts the value of this DateTime into a string representation.
Definition: DateTime.h:355
uint8_t UInt8
Definition: Bentley.r.h:116
DateTime const & DateTimeCR
Definition: DateTime.h:443
wchar_t const * WCharCP
Definition: Bentley.h:224
int16_t Int16
Definition: Bentley.r.h:117
Represents an instant in time, typically expressed as a date and time of day.
Definition: DateTime.h:28
uint32_t UInt32
Definition: Bentley.r.h:128
#define BEGIN_BENTLEY_NAMESPACE
Definition: Bentley.r.h:24
BentleyStatus
Definition: Bentley.h:208
DayOfWeek
Specifies the days of the week.
Definition: DateTime.h:66
Component
Specifies whether a DateTime represents a date (without time component) or a date time...
Definition: DateTime.h:53
uint64_t UInt64
Definition: Bentley.r.h:131
bool operator!=(const BentleyAllocator< _Ty > &, const BentleyAllocator< _Other > &)
Definition: BentleyAllocator.h:152
Utf8Char const * Utf8CP
Definition: Bentley.h:229
#define END_BENTLEY_NAMESPACE
Definition: Bentley.r.h:25
int64_t Int64
Definition: Bentley.r.h:130
Provides the metadata portion of a DateTime object.
Definition: DateTime.h:94
DateTime & DateTimeR
Definition: DateTime.h:442
Kind
Specifies whether a DateTime represents a local time, a Coordinated Universal Time (UTC)...
Definition: DateTime.h:36
CompareResult
Result of comparing two DateTimes.
Definition: DateTime.h:82
A string class that has many of the same capabilities as std::string, plus additional functions such ...
Definition: WString.h:51
bool operator==(const BentleyAllocator< _Ty > &, const BentleyAllocator< _Other > &)
Definition: BentleyAllocator.h:146

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.