Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Poco::DateTime Class Reference

#include <DateTime.h>

Public Types

enum  Months {
  JANUARY = 1 , FEBRUARY , MARCH , APRIL ,
  MAY , JUNE , JULY , AUGUST ,
  SEPTEMBER , OCTOBER , NOVEMBER , DECEMBER
}
 Symbolic names for month numbers (1 to 12). More...
 
enum  DaysOfWeek {
  SUNDAY = 0 , MONDAY , TUESDAY , WEDNESDAY ,
  THURSDAY , FRIDAY , SATURDAY
}
 Symbolic names for week day numbers (0 to 6). More...
 

Public Member Functions

 DateTime ()
 
 DateTime (const tm &tmStruct)
 Creates a DateTime for the current date and time.
 
 DateTime (const Timestamp &timestamp)
 Creates a DateTime from tm struct.
 
 DateTime (int year, int month, int day, int hour=0, int minute=0, int second=0, int millisecond=0, int microsecond=0)
 
 DateTime (double julianDay)
 
 DateTime (Timestamp::UtcTimeVal utcTime, Timestamp::TimeDiff diff)
 Creates a DateTime for the given Julian day.
 
 DateTime (const DateTime &dateTime)
 
 ~DateTime ()
 Copy constructor. Creates the DateTime from another one.
 
DateTimeoperator= (const DateTime &dateTime)
 Destroys the DateTime.
 
DateTimeoperator= (const Timestamp &timestamp)
 Assigns another DateTime.
 
DateTimeoperator= (double julianDay)
 Assigns a Timestamp.
 
DateTimeassign (int year, int month, int day, int hour=0, int minute=0, int second=0, int millisecond=0, int microseconds=0)
 Assigns a Julian day.
 
void swap (DateTime &dateTime)
 
int year () const
 Swaps the DateTime with another one.
 
int month () const
 Returns the year.
 
int week (int firstDayOfWeek=MONDAY) const
 Returns the month (1 to 12).
 
int day () const
 
int dayOfWeek () const
 Returns the day within the month (1 to 31).
 
int dayOfYear () const
 
int hour () const
 
int hourAMPM () const
 Returns the hour (0 to 23).
 
bool isAM () const
 Returns the hour (0 to 12).
 
bool isPM () const
 Returns true if hour < 12;.
 
int minute () const
 Returns true if hour >= 12.
 
int second () const
 Returns the minute (0 to 59).
 
int millisecond () const
 Returns the second (0 to 59).
 
int microsecond () const
 Returns the millisecond (0 to 999)
 
double julianDay () const
 Returns the microsecond (0 to 999)
 
Timestamp timestamp () const
 Returns the julian day for the date and time.
 
Timestamp::UtcTimeVal utcTime () const
 Returns the date and time expressed as a Timestamp.
 
bool operator== (const DateTime &dateTime) const
 
bool operator!= (const DateTime &dateTime) const
 
bool operator< (const DateTime &dateTime) const
 
bool operator<= (const DateTime &dateTime) const
 
bool operator> (const DateTime &dateTime) const
 
bool operator>= (const DateTime &dateTime) const
 
DateTime operator+ (const Timespan &span) const
 
DateTime operator- (const Timespan &span) const
 
Timespan operator- (const DateTime &dateTime) const
 
DateTimeoperator+= (const Timespan &span)
 
DateTimeoperator-= (const Timespan &span)
 
tm makeTM () const
 
void makeUTC (int tzd)
 Converts DateTime to tm struct.
 
void makeLocal (int tzd)
 Converts a local time into UTC, by applying the given time zone differential.
 

Static Public Member Functions

static bool isLeapYear (int year)
 Converts a UTC time into a local time, by applying the given time zone differential.
 
static int daysOfMonth (int year, int month)
 
static bool isValid (int year, int month, int day, int hour=0, int minute=0, int second=0, int millisecond=0, int microsecond=0)
 

Protected Member Functions

void computeGregorian (double julianDay)
 Computes the UTC time for a Julian day.
 
void computeDaytime ()
 

Static Protected Member Functions

static double toJulianDay (Timestamp::UtcTimeVal utcTime)
 
static double toJulianDay (int year, int month, int day, int hour=0, int minute=0, int second=0, int millisecond=0, int microsecond=0)
 Computes the Julian day for an UTC time.
 
static Timestamp::UtcTimeVal toUtcTime (double julianDay)
 

Private Member Functions

void checkLimit (short &lower, short &higher, short limit)
 Extracts the daytime (hours, minutes, seconds, etc.) from the stored utcTime.
 
void normalize ()
 

Private Attributes

Timestamp::UtcTimeVal _utcTime
 utility functions used to correct the overflow in computeGregorian
 
short _year
 
short _month
 
short _day
 
short _hour
 
short _minute
 
short _second
 
short _millisecond
 
short _microsecond
 

Detailed Description

This class represents an instant in time, expressed in years, months, days, hours, minutes, seconds and milliseconds based on the Gregorian calendar. The class is mainly useful for conversions between UTC, Julian day and Gregorian calendar dates.

The date and time stored in a DateTime is always in UTC (Coordinated Universal Time) and thus independent of the timezone in effect on the system.

Conversion calculations are based on algorithms collected and described by Peter Baum at http://vsg.cape.com/~pbaum/date/date0.htm

Internally, this class stores a date/time in two forms (UTC and broken down) for performance reasons. Only use this class for conversions between date/time representations. Use the Timestamp class for everything else.

Notes:

  • Zero is a valid year (in accordance with ISO 8601 and astronomical year numbering)
  • Year zero (0) is a leap year
  • Negative years (years preceding 1 BC) are not supported

For more information, please see:

Definition at line 32 of file DateTime.h.

Member Enumeration Documentation

◆ DaysOfWeek

Symbolic names for week day numbers (0 to 6).

Enumerator
SUNDAY 
MONDAY 
TUESDAY 
WEDNESDAY 
THURSDAY 
FRIDAY 
SATURDAY 

Definition at line 81 of file DateTime.h.

◆ Months

Symbolic names for month numbers (1 to 12).

Enumerator
JANUARY 
FEBRUARY 
MARCH 
APRIL 
MAY 
JUNE 
JULY 
AUGUST 
SEPTEMBER 
OCTOBER 
NOVEMBER 
DECEMBER 

Definition at line 64 of file DateTime.h.

Constructor & Destructor Documentation

◆ DateTime() [1/7]

Poco::DateTime::DateTime ( )

◆ DateTime() [2/7]

Poco::DateTime::DateTime ( const tm & tmStruct)

Creates a DateTime for the current date and time.

◆ DateTime() [3/7]

Poco::DateTime::DateTime ( const Timestamp & timestamp)

Creates a DateTime from tm struct.

◆ DateTime() [4/7]

Poco::DateTime::DateTime ( int year,
int month,
int day,
int hour = 0,
int minute = 0,
int second = 0,
int millisecond = 0,
int microsecond = 0 )

Creates a DateTime for the date and time given in a Timestamp.

◆ DateTime() [5/7]

Poco::DateTime::DateTime ( double julianDay)

Creates a DateTime for the given Gregorian date and time.

  • year is from 0 to 9999.
  • month is from 1 to 12.
  • day is from 1 to 31.
  • hour is from 0 to 23.
  • minute is from 0 to 59.
  • second is from 0 to 60.
  • millisecond is from 0 to 999.
  • microsecond is from 0 to 999.

Throws an InvalidArgumentException if an argument date is out of range.

◆ DateTime() [6/7]

Poco::DateTime::DateTime ( Timestamp::UtcTimeVal utcTime,
Timestamp::TimeDiff diff )

Creates a DateTime for the given Julian day.

◆ DateTime() [7/7]

Poco::DateTime::DateTime ( const DateTime & dateTime)

Creates a DateTime from an UtcTimeVal and a TimeDiff.

Mainly used internally by DateTime and friends.

◆ ~DateTime()

Poco::DateTime::~DateTime ( )

Copy constructor. Creates the DateTime from another one.

Member Function Documentation

◆ assign()

DateTime & Poco::DateTime::assign ( int year,
int month,
int day,
int hour = 0,
int minute = 0,
int second = 0,
int millisecond = 0,
int microseconds = 0 )

Assigns a Julian day.

◆ checkLimit()

void Poco::DateTime::checkLimit ( short & lower,
short & higher,
short limit )
private

Extracts the daytime (hours, minutes, seconds, etc.) from the stored utcTime.

◆ computeDaytime()

void Poco::DateTime::computeDaytime ( )
protected

Computes the Gregorian date for the given Julian day. See http://vsg.cape.com/~pbaum/date/injdimp.htm, section 3.3.1 for the algorithm.

◆ computeGregorian()

void Poco::DateTime::computeGregorian ( double julianDay)
protected

Computes the UTC time for a Julian day.

◆ day()

int Poco::DateTime::day ( ) const
inline

Returns the week number within the year. FirstDayOfWeek should be either SUNDAY (0) or MONDAY (1). The returned week number will be from 0 to 53. Week number 1 is the week containing January 4. This is in accordance to ISO 8601.

The following example assumes that firstDayOfWeek is MONDAY. For 2005, which started on a Saturday, week 1 will be the week starting on Monday, January 3. January 1 and 2 will fall within week 0 (or the last week of the previous year).

For 2007, which starts on a Monday, week 1 will be the week starting on Monday, January 1. There will be no week 0 in 2007.

Definition at line 333 of file DateTime.h.

◆ dayOfWeek()

int Poco::DateTime::dayOfWeek ( ) const

Returns the day within the month (1 to 31).

◆ dayOfYear()

int Poco::DateTime::dayOfYear ( ) const

Returns the weekday (0 to 6, where 0 = Sunday, 1 = Monday, ..., 6 = Saturday).

◆ daysOfMonth()

static int Poco::DateTime::daysOfMonth ( int year,
int month )
static

Returns true if the given year is a leap year; false otherwise.

◆ hour()

int Poco::DateTime::hour ( ) const
inline

Returns the number of the day in the year. January 1 is 1, February 1 is 32, etc.

Definition at line 339 of file DateTime.h.

◆ hourAMPM()

int Poco::DateTime::hourAMPM ( ) const
inline

Returns the hour (0 to 23).

Definition at line 345 of file DateTime.h.

◆ isAM()

bool Poco::DateTime::isAM ( ) const
inline

Returns the hour (0 to 12).

Definition at line 356 of file DateTime.h.

◆ isLeapYear()

bool Poco::DateTime::isLeapYear ( int year)
inlinestatic

Converts a UTC time into a local time, by applying the given time zone differential.

Definition at line 428 of file DateTime.h.

◆ isPM()

bool Poco::DateTime::isPM ( ) const
inline

Returns true if hour < 12;.

Definition at line 362 of file DateTime.h.

◆ isValid()

static bool Poco::DateTime::isValid ( int year,
int month,
int day,
int hour = 0,
int minute = 0,
int second = 0,
int millisecond = 0,
int microsecond = 0 )
static

Returns the number of days in the given month and year. Month is from 1 to 12.

◆ julianDay()

double Poco::DateTime::julianDay ( ) const

Returns the microsecond (0 to 999)

◆ makeLocal()

void Poco::DateTime::makeLocal ( int tzd)

Converts a local time into UTC, by applying the given time zone differential.

◆ makeTM()

tm Poco::DateTime::makeTM ( ) const

◆ makeUTC()

void Poco::DateTime::makeUTC ( int tzd)

Converts DateTime to tm struct.

◆ microsecond()

int Poco::DateTime::microsecond ( ) const
inline

Returns the millisecond (0 to 999)

Definition at line 386 of file DateTime.h.

◆ millisecond()

int Poco::DateTime::millisecond ( ) const
inline

Returns the second (0 to 59).

Definition at line 380 of file DateTime.h.

◆ minute()

int Poco::DateTime::minute ( ) const
inline

Returns true if hour >= 12.

Definition at line 368 of file DateTime.h.

◆ month()

int Poco::DateTime::month ( ) const
inline

Returns the year.

Definition at line 327 of file DateTime.h.

◆ normalize()

void Poco::DateTime::normalize ( )
private

◆ operator!=()

bool Poco::DateTime::operator!= ( const DateTime & dateTime) const
inline

Definition at line 398 of file DateTime.h.

◆ operator+()

DateTime Poco::DateTime::operator+ ( const Timespan & span) const

◆ operator+=()

DateTime & Poco::DateTime::operator+= ( const Timespan & span)

◆ operator-() [1/2]

Timespan Poco::DateTime::operator- ( const DateTime & dateTime) const

◆ operator-() [2/2]

DateTime Poco::DateTime::operator- ( const Timespan & span) const

◆ operator-=()

DateTime & Poco::DateTime::operator-= ( const Timespan & span)

◆ operator<()

bool Poco::DateTime::operator< ( const DateTime & dateTime) const
inline

Definition at line 404 of file DateTime.h.

◆ operator<=()

bool Poco::DateTime::operator<= ( const DateTime & dateTime) const
inline

Definition at line 410 of file DateTime.h.

◆ operator=() [1/3]

DateTime & Poco::DateTime::operator= ( const DateTime & dateTime)

Destroys the DateTime.

◆ operator=() [2/3]

DateTime & Poco::DateTime::operator= ( const Timestamp & timestamp)

Assigns another DateTime.

◆ operator=() [3/3]

DateTime & Poco::DateTime::operator= ( double julianDay)

Assigns a Timestamp.

◆ operator==()

bool Poco::DateTime::operator== ( const DateTime & dateTime) const
inline

Returns the date and time expressed in UTC-based time. UTC base time is midnight, October 15, 1582. Resolution is 100 nanoseconds.

Definition at line 392 of file DateTime.h.

◆ operator>()

bool Poco::DateTime::operator> ( const DateTime & dateTime) const
inline

Definition at line 416 of file DateTime.h.

◆ operator>=()

bool Poco::DateTime::operator>= ( const DateTime & dateTime) const
inline

Definition at line 422 of file DateTime.h.

◆ second()

int Poco::DateTime::second ( ) const
inline

Returns the minute (0 to 59).

Definition at line 374 of file DateTime.h.

◆ swap()

void Poco::DateTime::swap ( DateTime & dateTime)

Assigns a Gregorian date and time.

  • year is from 0 to 9999.
  • month is from 1 to 12.
  • day is from 1 to 31.
  • hour is from 0 to 23.
  • minute is from 0 to 59.
  • second is from 0 to 60.
  • millisecond is from 0 to 999.
  • microsecond is from 0 to 999.

Throws an InvalidArgumentException if an argument date is out of range.

+ Here is the caller graph for this function:

◆ timestamp()

Timestamp Poco::DateTime::timestamp ( ) const
inline

Returns the julian day for the date and time.

Definition at line 309 of file DateTime.h.

+ Here is the call graph for this function:

◆ toJulianDay() [1/2]

static double Poco::DateTime::toJulianDay ( int year,
int month,
int day,
int hour = 0,
int minute = 0,
int second = 0,
int millisecond = 0,
int microsecond = 0 )
staticprotected

Computes the Julian day for an UTC time.

◆ toJulianDay() [2/2]

double Poco::DateTime::toJulianDay ( Timestamp::UtcTimeVal utcTime)
inlinestaticprotected

Checks if the given date and time is valid (all arguments are within a proper range).

Returns true if all arguments are valid, false otherwise.

Definition at line 296 of file DateTime.h.

◆ toUtcTime()

Timestamp::UtcTimeVal Poco::DateTime::toUtcTime ( double julianDay)
inlinestaticprotected

Computes the Julian day for a Gregorian calendar date and time. See http://vsg.cape.com/~pbaum/date/jdimp.htm, section 2.3.1 for the algorithm.

Definition at line 303 of file DateTime.h.

◆ utcTime()

Timestamp::UtcTimeVal Poco::DateTime::utcTime ( ) const
inline

Returns the date and time expressed as a Timestamp.

Definition at line 315 of file DateTime.h.

◆ week()

int Poco::DateTime::week ( int firstDayOfWeek = MONDAY) const

Returns the month (1 to 12).

◆ year()

int Poco::DateTime::year ( ) const
inline

Swaps the DateTime with another one.

Definition at line 321 of file DateTime.h.

Member Data Documentation

◆ _day

short Poco::DateTime::_day
private

Definition at line 282 of file DateTime.h.

◆ _hour

short Poco::DateTime::_hour
private

Definition at line 283 of file DateTime.h.

◆ _microsecond

short Poco::DateTime::_microsecond
private

Definition at line 287 of file DateTime.h.

◆ _millisecond

short Poco::DateTime::_millisecond
private

Definition at line 286 of file DateTime.h.

◆ _minute

short Poco::DateTime::_minute
private

Definition at line 284 of file DateTime.h.

◆ _month

short Poco::DateTime::_month
private

Definition at line 281 of file DateTime.h.

◆ _second

short Poco::DateTime::_second
private

Definition at line 285 of file DateTime.h.

◆ _utcTime

Timestamp::UtcTimeVal Poco::DateTime::_utcTime
private

utility functions used to correct the overflow in computeGregorian

Definition at line 279 of file DateTime.h.

◆ _year

short Poco::DateTime::_year
private

Definition at line 280 of file DateTime.h.


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