sptk2 logo
SPTK Home Page
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
sptk::DateTime Class Reference

#include <DateTime.h>

Public Types

enum class  PrintAccuracy { MINUTES = 1 , SECONDS = 2 , MILLISECONDS = 3 }
 
enum class  Format {
  DATE_FORMAT , DATE_PARTS_ORDER , FULL_TIME_FORMAT , SHORT_TIME_FORMAT ,
  MONTH_NAME , WEEKDAY_NAME
}
 
using clock = std::chrono::system_clock
 
using time_point = std::chrono::system_clock::time_point
 
using duration = std::chrono::system_clock::duration
 

Public Member Functions

 DateTime (short y, short m, short d, short h=0, short mm=0, short s=0, short ms=0)
 
 DateTime (const char *dateStr=nullptr)
 
 DateTime (const DateTime &dt)=default
 
 DateTime (DateTime &&dt)=default
 
 DateTime (const time_point &dt)
 
 DateTime (const duration &dt)
 
const time_pointtimePoint () const
 
DateTimeoperator= (const DateTime &date)=default
 
void formatDate (std::ostream &str, int printFlags=0) const
 
void formatTime (std::ostream &str, int printFlags=0, PrintAccuracy printAccuracy=PrintAccuracy::SECONDS) const
 
duration sinceEpoch () const
 
int16_t daysInMonth () const
 
int16_t dayOfWeek () const
 
String dayOfWeekName () const
 
String monthName () const
 
DateTime date () const
 
String dateString (int printFlags=0) const
 
String timeString (int printFlags=0, PrintAccuracy printAccuracy=PrintAccuracy::SECONDS) const
 
String isoDateTimeString (PrintAccuracy printAccuracy=PrintAccuracy::SECONDS, bool gmt=false) const
 
 operator String () const
 
 operator time_t () const
 
void decodeDate (short *year, short *month, short *day, short *wday, short *yday, bool gmt=false) const
 
void decodeTime (short *h, short *m, short *s, short *ms, bool gmt=false) const
 
bool zero () const
 

Static Public Member Functions

static String format (Format dtFormat, size_t arg=0)
 
static char dateSeparator ()
 
static char timeSeparator ()
 
static bool time24Mode ()
 
static void time24Mode (bool t24mode)
 
static DateTime Now ()
 
static DateTime convertCTime (const time_t tt)
 
static std::chrono::minutes timeZoneOffset ()
 
static String timeZoneName ()
 
static bool isDaylightSavingsTime ()
 

Static Public Attributes

static constexpr int PF_RFC_DATE = 1
 
static constexpr int PF_TIMEZONE = 2
 
static constexpr int PF_12HOURS = 4
 
static constexpr int PF_GMT = 16
 

Friends

class DateTimeFormat
 

Detailed Description

Date and Time value.

Represents the date and time value. This value is stored as a floating point number. Allows to synchronize the Now() time with the external date/time, without affecting the local host system time.

Member Typedef Documentation

◆ clock

using sptk::DateTime::clock = std::chrono::system_clock

Clock used by DateTime

◆ duration

using sptk::DateTime::duration = std::chrono::system_clock::duration

DateTime::duration type definition

◆ time_point

using sptk::DateTime::time_point = std::chrono::system_clock::time_point

DateTime::time_point type definition

Member Enumeration Documentation

◆ PrintAccuracy

enum class sptk::DateTime::PrintAccuracy
strong

Time print accuracy

Constructor & Destructor Documentation

◆ DateTime() [1/6]

sptk::DateTime::DateTime ( short  y,
short  m,
short  d,
short  h = 0,
short  mm = 0,
short  s = 0,
short  ms = 0 
)

Constructor

Parameters
yYear
mMonth
dDay
hHour
mmMinute
sSecond
msMillisecond

◆ DateTime() [2/6]

sptk::DateTime::DateTime ( const char *  dateStr = nullptr)
explicit

Constructor

Parameters
dateStrDate string

◆ DateTime() [3/6]

sptk::DateTime::DateTime ( const DateTime dt)
default

Copy constructor

◆ DateTime() [4/6]

sptk::DateTime::DateTime ( DateTime &&  dt)
default

Move constructor

◆ DateTime() [5/6]

sptk::DateTime::DateTime ( const time_point dt)
explicit

Constructor

Parameters
dtTime point

◆ DateTime() [6/6]

sptk::DateTime::DateTime ( const duration dt)
explicit

Constructor

Parameters
dtDuration since epoch

Member Function Documentation

◆ convertCTime()

static DateTime sptk::DateTime::convertCTime ( const time_t  tt)
static

Converts C time into DateTime

Parameters
ttC time to convert

◆ date()

DateTime sptk::DateTime::date ( ) const

Reports the date part only

Referenced by sptk::CPopupCalendar::date().

◆ dateSeparator()

static char sptk::DateTime::dateSeparator ( )
static

System's date separator

◆ dateString()

String sptk::DateTime::dateString ( int  printFlags = 0) const

Returns date as a string

Parameters
printFlagsPrint flags, recognised { PF_GMT, PF_RFC_DATE }

◆ dayOfWeek()

int16_t sptk::DateTime::dayOfWeek ( ) const

Reports the day of the week in this date (1..7)

◆ dayOfWeekName()

String sptk::DateTime::dayOfWeekName ( ) const

Reports the day of the week name in this date ('Sunday'..'Saturday')

◆ daysInMonth()

int16_t sptk::DateTime::daysInMonth ( ) const

Reports the number of days in the month in this date (1..31)

◆ decodeDate()

void sptk::DateTime::decodeDate ( short *  year,
short *  month,
short *  day,
short *  wday,
short *  yday,
bool  gmt = false 
) const

Decodes date into y,m,d

◆ decodeTime()

void sptk::DateTime::decodeTime ( short *  h,
short *  m,
short *  s,
short *  ms,
bool  gmt = false 
) const

Decodes time into h,m,s,ms

◆ format()

static String sptk::DateTime::format ( Format  dtFormat,
size_t  arg = 0 
)
static

System's format info

Parameters
dtFormatFormat type
argOptional format argument, for MONTH_NAME and WEEKDAY_NAME

◆ formatDate()

void sptk::DateTime::formatDate ( std::ostream &  str,
int  printFlags = 0 
) const

Print the date into stream

Parameters
strOutput stream
printFlagsPrint flags, recognised { PF_GMT, PF_RFC_DATE }

◆ formatTime()

void sptk::DateTime::formatTime ( std::ostream &  str,
int  printFlags = 0,
PrintAccuracy  printAccuracy = PrintAccuracy::SECONDS 
) const

Print date into string

Parameters
strOutput stream
printFlagsPrint flags, recognised { PF_GMT, PF_TIMEZONE, PF_12HOURS }
printAccuracyPrint accuracy,
See also
PrintAccuracy

◆ isDaylightSavingsTime()

static bool sptk::DateTime::isDaylightSavingsTime ( )
static

Returns true if daylight savings time

Returns
true if daylight savings time

◆ isoDateTimeString()

String sptk::DateTime::isoDateTimeString ( PrintAccuracy  printAccuracy = PrintAccuracy::SECONDS,
bool  gmt = false 
) const

Returns time as a ISO date and time string

Parameters
printAccuracyPrint accuracy,
See also
PrintAccuracy
Parameters
gmtIf true print GMT time

◆ monthName()

String sptk::DateTime::monthName ( ) const

Reports the month name in this date ('Sunday'..'Saturday')

◆ Now()

static DateTime sptk::DateTime::Now ( )
static

Reports the current date and time.

◆ operator String()

sptk::DateTime::operator String ( ) const
inlineexplicit

Returns date and time as a string

◆ operator time_t()

sptk::DateTime::operator time_t ( ) const
inlineexplicit

Returns time_t presentation

◆ operator=()

DateTime & sptk::DateTime::operator= ( const DateTime date)
default

Assignment

◆ sinceEpoch()

duration sptk::DateTime::sinceEpoch ( ) const
inline

Duration since epoch

◆ time24Mode() [1/2]

static bool sptk::DateTime::time24Mode ( )
static

Returns system's time mode.

◆ time24Mode() [2/2]

static void sptk::DateTime::time24Mode ( bool  t24mode)
static

Sets system's time mode

◆ timePoint()

const time_point & sptk::DateTime::timePoint ( ) const
inline

Returns time_point presentation of the date and time

◆ timeSeparator()

static char sptk::DateTime::timeSeparator ( )
static

System's time separator

◆ timeString()

String sptk::DateTime::timeString ( int  printFlags = 0,
PrintAccuracy  printAccuracy = PrintAccuracy::SECONDS 
) const

Returns time as a string

Parameters
printFlagsPrint flags, recognised { PF_GMT, PF_TIMEZONE, PF_12HOURS }
printAccuracyPrint accuracy,
See also
PrintAccuracy

◆ timeZoneName()

static String sptk::DateTime::timeZoneName ( )
static

Returns timezone name

Returns
timezone name

◆ timeZoneOffset()

static std::chrono::minutes sptk::DateTime::timeZoneOffset ( )
static

Returns timezone offset in minutes

Returns
timezone offset in minutes

◆ zero()

bool sptk::DateTime::zero ( ) const
inline

Return true if date and time are at epoch

Member Data Documentation

◆ PF_RFC_DATE

constexpr int sptk::DateTime::PF_RFC_DATE = 1
staticconstexpr

Date and time print flags


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

Fri Oct 14 2022 09:58:42: SPTK 5.4.1