azure-core
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Azure::DateTime Class Referencefinal

Manages date and time in standardized string formats. More...

#include <datetime.hpp>

Inheritance diagram for Azure::DateTime:

Public Types

enum class  TimeFractionFormat { DropTrailingZeros , AllDigits , Truncate }
 Defines the format applied to the fraction part of any Azure::DateTime. More...
 
enum class  DateFormat { Rfc1123 , Rfc3339 }
 Defines the supported date and time string formats. More...
 

Public Member Functions

constexpr DateTime ()
 Constructs a default instance of DateTime (00:00:00.0000000 on January 1st, 0001).
 
 DateTime (int16_t year, int8_t month=1, int8_t day=1, int8_t hour=0, int8_t minute=0, int8_t second=0)
 Constructs an instance of DateTime.
 
constexpr DateTime (time_point const &timePoint)
 Constructs an instance of DateTime from a time_point.
 
 DateTime (std::chrono::system_clock::time_point const &systemTime)
 Construct an instance of DateTime from std::chrono::system_clock::time_point.
 
 operator std::chrono::system_clock::time_point () const
 Convert an instance of Azure::DateTime to std::chrono::system_clock::time_point.
 
std::string ToString (DateFormat format=DateFormat::Rfc3339) const
 Get a string representation of the Azure::DateTime.
 
std::string ToString (DateFormat format, TimeFractionFormat fractionFormat) const
 Get a string representation of the Azure::DateTime.
 

Static Public Member Functions

static DateTime Parse (std::string const &dateTime, DateFormat format)
 Create Azure::DateTime from a string representing time in UTC in the specified format.
 

Detailed Description

Supports date range from year 0001 to end of year 9999 with 100ns (7 decimal places for fractional second) precision.

Remarks
std::chrono::system_clock::time_point can't be used, because there is no guarantees for the date range and precision.
This class is supposed to be able to handle a DateTime that comes over the wire.

Member Enumeration Documentation

◆ DateFormat

enum class Azure::DateTime::DateFormat
strong
Enumerator
Rfc1123 

RFC 1123.

Rfc3339 

RFC 3339.

◆ TimeFractionFormat

Enumerator
DropTrailingZeros 

Include only meaningful fractional time digits, up to and excluding trailing zeroes.

AllDigits 

Include all the fractional time digits up to maximum precision, even if the entire value is zero.

Truncate 

Drop all the fractional time digits.

Constructor & Destructor Documentation

◆ DateTime() [1/4]

constexpr Azure::DateTime::DateTime ( )
inlineconstexpr

◆ DateTime() [2/4]

Azure::DateTime::DateTime ( int16_t  year,
int8_t  month = 1,
int8_t  day = 1,
int8_t  hour = 0,
int8_t  minute = 0,
int8_t  second = 0 
)
inlineexplicit
Parameters
yearYear.
monthMonth.
dayDay.
hourHour.
minuteMinute.
secondSeconds.
Exceptions
std::invalid_argumentIf any parameter is invalid.

◆ DateTime() [3/4]

constexpr Azure::DateTime::DateTime ( time_point const &  timePoint)
inlineconstexpr

◆ DateTime() [4/4]

Azure::DateTime::DateTime ( std::chrono::system_clock::time_point const &  systemTime)
inline
Parameters
systemTimeA value of std::chrono::system_clock::time_point.

Member Function Documentation

◆ operator std::chrono::system_clock::time_point()

DateTime::operator std::chrono::system_clock::time_point ( ) const
explicit
Exceptions
std::invalid_argumentif Azure::DateTime is outside of the range that can be represented.

◆ Parse()

DateTime DateTime::Parse ( std::string const &  dateTime,
DateFormat  format 
)
static
Parameters
dateTimeA string with the date and time.
formatA format to which dateTime string adheres to.
Returns
Azure::DateTime that was constructed from the dateTime string.
Exceptions
std::invalid_argumentIf format is not recognized, or if parsing error.

◆ ToString() [1/2]

std::string DateTime::ToString ( DateFormat  format,
TimeFractionFormat  fractionFormat 
) const
Parameters
formatThe representation format to use.
fractionFormatThe format for the fraction part of the DateTime. Only supported by RFC3339.
Exceptions
std::invalid_argumentIf year exceeds 9999, or if format is not recognized.

◆ ToString() [2/2]

std::string DateTime::ToString ( DateFormat  format = DateFormat::Rfc3339) const
Parameters
formatThe representation format to use, defaulted to use RFC 3339.
Exceptions
std::invalid_argumentIf year exceeds 9999, or if format is not recognized.

The documentation for this class was generated from the following files: