MeteoIODoc  2.10.0
mio::Date Class Reference

Detailed Description

A class to handle timestamps. This class handles conversion between different time display formats (ISO, numeric) as well as different time representation (julian date, modified julian date, etc). It also handles time zones as well as very basic Daylight Saving Time (DST). Since the activation dates of DST are political and not technical, it can not be automatically calculated. Therefore, it has to be provided by the caller: when the dst flag is set, the dst time shift is automatically applied. When the dst flag ceases to be set, the dst time shift is no longer applied. This is very crude, but please keep in mind that using DST for monitoring data is usually a bad idea... Finally, we assume that dates are positive. If this would not be the case, this class has to be recompiled with the proper define.

Internally, the date is stored as true julian date in GMT. The maximal precision is 0.01 second (however with the limitation that leap seconds are currently not handled).

Please see Date::FORMATS for supported display formats and http://en.wikipedia.org/wiki/Julian_day for the various date representation definitions. The following date representation are currently supported:

When parsing a string to extract a date (using IOUtils::convertString), various string representations are supported (the timezone term {TZ} is optional if a fallback timezone is available, most probably as Input::TIME_ZONE in the configuration file) with their reduced accuracy variations (see below):

  • ISO 8601 variations:
    • YYYY-MM-DDThh:mm:ss{TZ}, for example 2017-02-02T12:35:00 in the fallback time zone
    • YYYY-MM-DDThh:mm{TZ}, for example 2017-02-02T12:35+01:00
  • similar to ISO but without the 'T' marker (some systems wrongfully reject it):
    • YYYY-MM-DD hh:mm:ss{TZ}, for example 2017-02-02 11:35:00Z
    • YYYY-MM-DD hh:mm{TZ}, for example 2017-02-02 12:35+01
  • simplified:
    • YYYY-MM-DD{TZ}, for example 2017-02-01
    • hh:mm{TZ}, for example 15:12+01:30
  • numeric:
    • YYYYMMDDHHmmss{TZ}
    • YYYYMMDDHHmm{TZ}
    • YYYYMMDDHH{TZ}
  • relative, with keyword (in this case a fallback time zone must be available from somewhere else):
    • NOW
    • NOW±{offset} (the offset is in seconds), for example NOW+3600
    • NOW±hh:mm (the offset is in hours and minutes), for example NOW-01:30

The timezone information {TZ} is as laid out in Date::parseTimeZone. Reduced accuracy means that any number of values may be dropped from the last to the most significant from the date and time representation.

Author
Mathias Bavay
Date
2010-04-15

#include <Date.h>

Public Types

enum  FORMATS {
  ISO , ISO_TZ , ISO_Z , FULL ,
  NUM , DIN , ISO_WEEK , ISO_DATE
}
 Keywords for selecting the date formats (the subsecond resolution is dropped when not needed) More...
 
enum  RND { UP , DOWN , CLOSEST }
 Keywords for selecting rounding strategy. More...
 

Public Member Functions

 Date ()
 Default constructor: timezone is set to GMT without DST, julian date is set to 0 (meaning -4713-01-01T12:00) More...
 
 Date (const double &in_timezone)
 Current date constructor: the object is created with the current system date and time. More...
 
 Date (const double &julian_in, const double &in_timezone)
 Julian date constructor. More...
 
 Date (const int &year, const int &month, const int &day, const int &hour, const int &minute, const double &in_timezone)
 Date constructor by elements. All values are checked for plausibility. More...
 
 Date (const int &year, const int &month, const int &day, const int &hour, const int &minute, const int &second, const double &in_timezone)
 
 Date (const int &year, const int &month, const int &day, const int &hour, const int &minute, const double &second, const double &in_timezone)
 
 Date (const time_t &)
 Unix date constructor. More...
 
 Date (const int &year, const double &jdn, const double &in_timezone)
 Julian Day Number (JDN) constructor. More...
 
void setFromSys ()
 Set internal gmt time from system time as well as system time zone. More...
 
void setTimeZone (const double &in_timezone)
 Set timezone and Daylight Saving Time flag. More...
 
void setDate (const Date &in_date)
 Copy setter. More...
 
void setDate (const double &julian_in, const double &in_timezone)
 Set date from a julian date (JD). More...
 
void setDate (const int &year, const int &month, const int &day, const int &hour, const int &minute, const double &in_timezone)
 Set date by elements. All values are checked for plausibility. More...
 
void setDate (const int &year, const int &month, const int &day, const int &hour, const int &minute, const int &second, const double &in_timezone)
 Set date by elements. All values are checked for plausibility. More...
 
void setDate (const int &year, const int &month, const int &day, const int &hour, const int &minute, const double &second, const double &in_timezone)
 Set date by elements. All values are checked for plausibility. More...
 
void setDate (const int &year, const unsigned int &month, const unsigned int &day, const unsigned int &hour, const unsigned int &minute, const double &in_timezone)
 
void setDate (const int &year, const unsigned int &month, const unsigned int &day, const unsigned int &hour, const unsigned int &minute, const unsigned int &second, const double &in_timezone)
 
void setDate (const int &year, const unsigned int &month, const unsigned int &day, const unsigned int &hour, const unsigned int &minute, const double &second, const double &in_timezone)
 
void setDate (const int &year, const double &jdn, const double &in_timezone)
 Set date from a year and Julian Day Number (JDN). More...
 
void setDate (const time_t &in_time)
 Set date from a Unix date. More...
 
void setModifiedJulianDate (const double &julian_in, const double &in_timezone)
 Set date from a modified julian date (MJD). More...
 
void setRFC868Date (const double &julian_in, const double &in_timezone)
 Set date from an RFC868 date (time since 1900-01-01T00:00 GMT, valid until 2036). More...
 
void setUnixDate (const time_t &in_time)
 Set date from a Unix date. More...
 
void setExcelDate (const double excel_in, const double &in_timezone)
 Set date from an Excel date. More...
 
void setMatlabDate (const double matlab_in, const double &in_timezone)
 Set date from an Matlab date. More...
 
void setUndef (const bool &flag=true)
 
bool isUndef () const
 
double getTimeZone () const
 Returns timezone. More...
 
double getJulian (const bool &gmt=false) const
 Return julian date (JD). The julian date is defined as the fractional number of days since -4713-01-01T12:00 UTC. More...
 
double getModifiedJulianDate (const bool &gmt=false) const
 Return modified julian date (MJD). The modified julian date is defined as the fractional number of days since 1858-11-17T00:00 UTC (definition by the Smithsonian Astrophysical Observatory, MA). More...
 
double getTruncatedJulianDate (const bool &gmt=false) const
 Return truncated julian date (TJD). The truncated julian date is defined as the julian day shifted to start at 00:00 and modulo 10000 days. The last origin (ie: 0) was 1995-10-10T00:00 (definition by National Institute of Standards and Technology). More...
 
double getRFC868Date (const bool &gmt=false) const
 Return RFC868 date. The RFC868 date is defined as the fractional number of days since 1900-01-01T00:00 GMT. More...
 
time_t getUnixDate () const
 Return Unix time (or POSIX time). The Unix time is defined as the number of seconds since 1970-01-01T00:00 UTC (Unix Epoch). It is therefore ALWAYS in GMT. (defined as IEEE P1003.1 POSIX. See http://www.mail-archive.com/leapsecs@rom.usno.navy.mil/msg00109.html for some technical, historical and funny insight into the standardization process) More...
 
double getExcelDate (const bool &gmt=false) const
 Return Excel date. The (sick) Excel date is defined as the number of days since 1900-01-00T00:00 (no, this is NOT a typo). Moreover, it (wrongly) considers that 1900 was a leap year (in order to remain compatible with an old Lotus123 bug). This practically means that for dates after 1900-03-01, an Excel date really represents the number of days since 1900-01-01T00:00 PLUS 2. More...
 
double getMatlabDate (const bool &gmt=false) const
 Return Matlab date. This is the number of days since 0000-01-01T00:00:00. See http://www.mathworks.com/help/techdoc/ref/datenum.html. More...
 
void getDate (double &julian_out, const bool &gmt=false) const
 Retrieve julian date. This method is a candidate for deletion: it should now be obsolete. More...
 
void getDate (int &year, int &month, int &day, const bool &gmt=false) const
 Return year, month, day. More...
 
void getDate (int &year, int &month, int &day, int &hour, const bool &gmt=false) const
 Return year, month, day. More...
 
void getDate (int &year, int &month, int &day, int &hour, int &minute, const bool &gmt=false) const
 Return year, month, day. More...
 
void getDate (int &year, int &month, int &day, int &hour, int &minute, double &second, const bool &gmt=false) const
 Return year, month, day. More...
 
void getDate (int &year, int &month, int &day, int &hour, int &minute, int &second, const bool &gmt=false) const
 
void getTime (int &hour_out, int &minute_out, const bool &gmt=false) const
 Return time of the day. More...
 
void getTime (int &hour_out, int &minute_out, double &second_out, const bool &gmt=false) const
 Return time of the day. More...
 
int getYear (const bool &gmt=false) const
 Return year. More...
 
unsigned short getDayOfWeek (const bool &gmt=false) const
 Return the day of the week for the current date. The day of the week is between 1 (Monday) and 7 (Sunday). More...
 
unsigned short getISOWeekNr (const bool &gmt=false) const
 Return the ISO 8601 week number The week number range from 1 to 53 for a leap year. The first week is the week that contains the first Thursday of the year. Previous days are attributed to the last week of the previous year (See https://en.wikipedia.org/wiki/ISO_week_date). More...
 
unsigned short getISOWeekNr (int &ISO_year, const bool &gmt=false) const
 Return the ISO 8601 week number The week number range from 1 to 53 for a leap year. The first week is the week that contains the first Thursday of the year. Previous days are attributed to the last week of the previous year (See https://en.wikipedia.org/wiki/ISO_week_date). More...
 
int getJulianDayNumber (const bool &gmt=false) const
 Return the julian day for the current date. Return the day of the year index for the current Date object. More...
 
bool isLeapYear () const
 Return true if the current year is a leap year. More...
 
void rnd (const double &precision, const RND &type=CLOSEST)
 Round date to a given precision. More...
 
const std::string toString (const FORMATS &type, const bool &gmt=false) const
 Return a nicely formated string. More...
 
const std::string toString () const
 
bool operator== (const Date &) const
 
bool operator!= (const Date &) const
 
bool operator< (const Date &) const
 
bool operator<= (const Date &) const
 
bool operator> (const Date &) const
 
bool operator>= (const Date &) const
 
Dateoperator+= (const Date &)
 
Dateoperator-= (const Date &)
 
Dateoperator+= (const double &)
 
Dateoperator-= (const double &)
 
Dateoperator*= (const double &)
 
Dateoperator/= (const double &)
 
const Date operator+ (const Date &) const
 
const Date operator- (const Date &) const
 
const Date operator+ (const double &) const
 
const Date operator- (const double &) const
 
const Date operator* (const double &) const
 
const Date operator/ (const double &) const
 

Static Public Member Functions

static unsigned int mod (const double &julian, const unsigned int &seconds)
 Modulus of a julian date by a given number of seconds. This returns the modulus (in seconds) of a given date by the given number of seconds. More...
 
static unsigned int mod (const Date &indate, const unsigned int &seconds)
 Modulus of a date by a given number of seconds. This returns the modulus (in seconds) of a given date by the given number of seconds. More...
 
static double rnd (const double &julian, const double &precision, const RND &type=CLOSEST)
 Round a julian date to a given precision. If you want to round a local date, do NOT provide it as gmt julian but as local julian, otherwise things like rounding to the next day would be shifted by TimeZone. More...
 
static const Date rnd (const Date &indate, const double &precision, const RND &type=CLOSEST)
 
static double parseTimeZone (const std::string &timezone_iso)
 Parse an ISO 8601 formatted time zone specification. Time zones MUST be specified right after a date/time/combined representation according to the following formats: More...
 
static std::string printFractionalDay (const double &fractional)
 Nicely format an hour given as fractional day into a human readable hour. More...
 

Static Public Attributes

static const double DST_shift = 1.0
 
static const double MJD_offset = 2400000.5
 offset between julian date and modified julian date More...
 
static const double RFC868_offset = 2415020.5
 offset between julian date and RFC868 time (ref is 1900-01-01T00:00 GMT) More...
 
static const double Unix_offset = 2440587.5
 offset between julian date and Unix Epoch time More...
 
static const double Excel_offset = 2415018.5
 offset between julian date and Excel dates (note that excel invented some days...) More...
 
static const double Matlab_offset = 1721058.5
 offset between julian date and Matlab dates More...
 
static const double epsilon_sec = 0.01
 
static const double epsilon = epsilon_sec / (24.*3600.025)
 minimum difference between two dates in days. 3600.025 is intentional to support high sampling rates More...
 

Protected Member Functions

double localToGMT (const double &in_julian) const
 
double GMTToLocal (const double &in_gmt_julian) const
 

Static Protected Member Functions

static double calculateJulianDate (const int &in_year, const int &in_month, const int &in_day, const int &in_hour, const int &in_minute, const double &i_second)
 
static void calculateDate (const double &i_julian, int &out_year, int &out_month, int &out_day)
 Calculate the date components (y,m,d) from a given julian date. More...
 
static void calculateTime (const double &i_julian, int &o_hour, int &o_minute, double &o_second)
 Calculate the time components (y,m,d) from a given julian date. More...
 
static void calculateValues (const double &i_julian, int &out_year, int &out_month, int &out_day, int &out_hour, int &out_minute, double &o_second)
 
static long getJulianDayNumber (const int &, const int &, const int &)
 
static bool isLeapYear (const int &)
 
static void plausibilityCheck (const int &in_year, const int &in_month, const int &in_day, const int &in_hour, const int &in_minute, const double &in_second)
 
static bool initStaticData ()
 initialize the static map TZAbbrev More...
 

Protected Attributes

double timezone
 
double gmt_julian
 
bool undef
 

Static Protected Attributes

static std::map< std::string, double > TZAbbrev
 
static const int daysLeapYear [] = {31,29,31,30,31,30,31,31,30,31,30,31}
 
static const int daysNonLeapYear [] = {31,28,31,30,31,30,31,31,30,31,30,31}
 
static const bool __init = Date::initStaticData()
 

Friends

std::ostream & operator<< (std::ostream &os, const Date &date)
 
std::istream & operator>> (std::istream &is, Date &date)
 

Member Enumeration Documentation

◆ FORMATS

Keywords for selecting the date formats (the subsecond resolution is dropped when not needed)

Enumerator
ISO 

ISO 8601 extended format combined date: YYYY-MM-DDTHH:mm:SS.sss (fields might be dropped, in the least to the most significant order)

ISO_TZ 

ISO 8601 format (same as ISO) but with time zone specification.

ISO_Z 

ISO 8601 format, forcing GMT and Zulu (Z) timezone specification.

FULL 

ISO 8601 followed by the julian date (in parenthesis)

NUM 

ISO 8601 basic format date: YYYYMMDDHHmmSS (fields might be dropped, in the least to the most significant order)

DIN 

DIN5008 format: DD.MM.YYYY HH:MM:SS.sss.

ISO_WEEK 

ISO 8601 week date: YYYY-Www-D (for example: 2014-W41-1)

ISO_DATE 

ISO 8601 date format without the time (ie YYYY-MM-DD)

◆ RND

Keywords for selecting rounding strategy.

Enumerator
UP 

rounding toward highest absolute value

DOWN 

rounding toward smallest absolute value

CLOSEST 

rounding toward closest

Constructor & Destructor Documentation

◆ Date() [1/8]

mio::Date::Date ( )

Default constructor: timezone is set to GMT without DST, julian date is set to 0 (meaning -4713-01-01T12:00)

◆ Date() [2/8]

mio::Date::Date ( const double &  in_timezone)

Current date constructor: the object is created with the current system date and time.

Parameters
in_timezonetimezone as an offset to GMT (in hours)

◆ Date() [3/8]

mio::Date::Date ( const double &  julian_in,
const double &  in_timezone 
)

Julian date constructor.

Parameters
julian_injulian date to set
in_timezonetimezone as an offset to GMT (in hours)

◆ Date() [4/8]

mio::Date::Date ( const int &  in_year,
const int &  in_month,
const int &  in_day,
const int &  in_hour,
const int &  in_minute,
const double &  in_timezone 
)

Date constructor by elements. All values are checked for plausibility.

Parameters
in_yearin 4 digits
in_monthplease keep in mind that first month of the year is 1 (ie: not 0!)
in_dayplease keep in mind that first day of the month is 1 (ie: not 0!)
in_hour
in_minute
in_timezonetimezone as an offset to GMT (in hours, optional)

◆ Date() [5/8]

mio::Date::Date ( const int &  year,
const int &  month,
const int &  day,
const int &  hour,
const int &  minute,
const int &  second,
const double &  in_timezone 
)

◆ Date() [6/8]

mio::Date::Date ( const int &  year,
const int &  month,
const int &  day,
const int &  hour,
const int &  minute,
const double &  second,
const double &  in_timezone 
)

◆ Date() [7/8]

mio::Date::Date ( const time_t &  in_time)

Unix date constructor.

Parameters
in_timeunix time (ie: as number of seconds since Unix Epoch, always UTC)

◆ Date() [8/8]

mio::Date::Date ( const int &  year,
const double &  jdn,
const double &  in_timezone 
)

Julian Day Number (JDN) constructor.

Parameters
yearyear to set
jdnJulian Day Number within the provided year
in_timezonetimezone as an offset to GMT (in hours, optional)

Member Function Documentation

◆ calculateDate()

void mio::Date::calculateDate ( const double &  i_julian,
int &  o_year,
int &  o_month,
int &  o_day 
)
staticprotected

Calculate the date components (y,m,d) from a given julian date.

This comes from Fliegel, H. F. and van Flandern, T. C. 1968. Letters to the editor: a machine algorithm for processing calendar dates; Commun. ACM 11, 10 (Oct. 1968), 657. DOI= http://doi.acm.org/10.1145/364096.364097

Parameters
[in]i_julianjulian date
[out]o_yearthe extracted year
[out]o_monththe extracted month
[out]o_daythe extracted day

◆ calculateJulianDate()

double mio::Date::calculateJulianDate ( const int &  in_year,
const int &  in_month,
const int &  in_day,
const int &  in_hour,
const int &  in_minute,
const double &  i_second 
)
staticprotected

◆ calculateTime()

void mio::Date::calculateTime ( const double &  i_julian,
int &  o_hour,
int &  o_minute,
double &  o_second 
)
staticprotected

Calculate the time components (y,m,d) from a given julian date.

Parameters
[in]i_julianjulian date
[out]o_hourthe extracted hour of the day
[out]o_minutethe extracted minutes
[out]o_secondthe extracted seconds

◆ calculateValues()

void mio::Date::calculateValues ( const double &  i_julian,
int &  out_year,
int &  out_month,
int &  out_day,
int &  out_hour,
int &  out_minute,
double &  o_second 
)
staticprotected

◆ getDate() [1/6]

void mio::Date::getDate ( double &  julian_out,
const bool &  gmt = false 
) const

Retrieve julian date. This method is a candidate for deletion: it should now be obsolete.

Parameters
julian_outjulian date (in local time zone or GMT depending on the gmt flag)
gmtconvert returned value to GMT? (default: false)

◆ getDate() [2/6]

void mio::Date::getDate ( int &  year_out,
int &  month_out,
int &  day_out,
const bool &  gmt = false 
) const

Return year, month, day.

Parameters
year_out
month_out
day_out
gmtconvert returned value to GMT? (default: false)

◆ getDate() [3/6]

void mio::Date::getDate ( int &  year_out,
int &  month_out,
int &  day_out,
int &  hour_out,
const bool &  gmt = false 
) const

Return year, month, day.

Parameters
year_out
month_out
day_out
hour_out
gmtconvert returned value to GMT? (default: false)

◆ getDate() [4/6]

void mio::Date::getDate ( int &  year_out,
int &  month_out,
int &  day_out,
int &  hour_out,
int &  minute_out,
const bool &  gmt = false 
) const

Return year, month, day.

Parameters
year_out
month_out
day_out
hour_out
minute_out
gmtconvert returned value to GMT? (default: false)

◆ getDate() [5/6]

void mio::Date::getDate ( int &  year_out,
int &  month_out,
int &  day_out,
int &  hour_out,
int &  minute_out,
double &  second_out,
const bool &  gmt = false 
) const

Return year, month, day.

Parameters
year_out
month_out
day_out
hour_out
minute_out
second_out
gmtconvert returned value to GMT? (default: false)

◆ getDate() [6/6]

void mio::Date::getDate ( int &  year,
int &  month,
int &  day,
int &  hour,
int &  minute,
int &  second,
const bool &  gmt = false 
) const

◆ getDayOfWeek()

unsigned short mio::Date::getDayOfWeek ( const bool &  gmt = false) const

Return the day of the week for the current date. The day of the week is between 1 (Monday) and 7 (Sunday).

Parameters
gmtconvert returned value to GMT? (default: false)
Returns
day of the week in [1, 7]

◆ getExcelDate()

double mio::Date::getExcelDate ( const bool &  gmt = false) const

Return Excel date. The (sick) Excel date is defined as the number of days since 1900-01-00T00:00 (no, this is NOT a typo). Moreover, it (wrongly) considers that 1900 was a leap year (in order to remain compatible with an old Lotus123 bug). This practically means that for dates after 1900-03-01, an Excel date really represents the number of days since 1900-01-01T00:00 PLUS 2.

Parameters
gmtconvert returned value to GMT? (default: false)
Returns
Excel date in the current timezone / in GMT depending on the gmt parameter

◆ getISOWeekNr() [1/2]

unsigned short mio::Date::getISOWeekNr ( const bool &  gmt = false) const

Return the ISO 8601 week number The week number range from 1 to 53 for a leap year. The first week is the week that contains the first Thursday of the year. Previous days are attributed to the last week of the previous year (See https://en.wikipedia.org/wiki/ISO_week_date).

Parameters
gmtconvert returned value to GMT? (default: false)
Returns
ISO 8601 week number in [1, 53]

◆ getISOWeekNr() [2/2]

unsigned short mio::Date::getISOWeekNr ( int &  ISO_year,
const bool &  gmt = false 
) const

Return the ISO 8601 week number The week number range from 1 to 53 for a leap year. The first week is the week that contains the first Thursday of the year. Previous days are attributed to the last week of the previous year (See https://en.wikipedia.org/wiki/ISO_week_date).

Parameters
[out]ISO_yearget filled with the matching ISO year (since the fist/last few days might belong to the previous/next year)
gmtconvert returned value to GMT? (default: false)
Returns
ISO 8601 week number in [1, 53]

◆ getJulian()

double mio::Date::getJulian ( const bool &  gmt = false) const

Return julian date (JD). The julian date is defined as the fractional number of days since -4713-01-01T12:00 UTC.

Parameters
gmtconvert returned value to GMT? (default: false)
Returns
julian date in the current timezone / in GMT depending on the gmt parameter

◆ getJulianDayNumber() [1/2]

int mio::Date::getJulianDayNumber ( const bool &  gmt = false) const

Return the julian day for the current date. Return the day of the year index for the current Date object.

Parameters
gmtconvert returned value to GMT? (default: false)
Returns
julian day number, starting from 1

◆ getJulianDayNumber() [2/2]

long mio::Date::getJulianDayNumber ( const int &  i_year,
const int &  i_month,
const int &  i_day 
)
staticprotected

◆ getMatlabDate()

double mio::Date::getMatlabDate ( const bool &  gmt = false) const

Return Matlab date. This is the number of days since 0000-01-01T00:00:00. See http://www.mathworks.com/help/techdoc/ref/datenum.html.

Parameters
gmtconvert returned value to GMT? (default: false)
Returns
Matlab date in the current timezone / in GMT depending on the gmt parameter

◆ getModifiedJulianDate()

double mio::Date::getModifiedJulianDate ( const bool &  gmt = false) const

Return modified julian date (MJD). The modified julian date is defined as the fractional number of days since 1858-11-17T00:00 UTC (definition by the Smithsonian Astrophysical Observatory, MA).

Parameters
gmtconvert returned value to GMT? (default: false)
Returns
modified julian date in the current timezone / in GMT depending on the gmt parameter

◆ getRFC868Date()

double mio::Date::getRFC868Date ( const bool &  gmt = false) const

Return RFC868 date. The RFC868 date is defined as the fractional number of days since 1900-01-01T00:00 GMT.

Parameters
gmtconvert returned value to GMT? (default: false)
Returns
RFC868 julian date in the current timezone / in GMT depending on the gmt parameter

◆ getTime() [1/2]

void mio::Date::getTime ( int &  hour_out,
int &  minute_out,
const bool &  gmt = false 
) const

Return time of the day.

Parameters
hour_out
minute_out
gmtconvert returned value to GMT? (default: false)

◆ getTime() [2/2]

void mio::Date::getTime ( int &  hour_out,
int &  minute_out,
double &  second_out,
const bool &  gmt = false 
) const

Return time of the day.

Parameters
hour_out
minute_out
second_out
gmtconvert returned value to GMT? (default: false)

◆ getTimeZone()

double mio::Date::getTimeZone ( ) const

Returns timezone.

Returns
timezone as an offset to GMT

◆ getTruncatedJulianDate()

double mio::Date::getTruncatedJulianDate ( const bool &  gmt = false) const

Return truncated julian date (TJD). The truncated julian date is defined as the julian day shifted to start at 00:00 and modulo 10000 days. The last origin (ie: 0) was 1995-10-10T00:00 (definition by National Institute of Standards and Technology).

Parameters
gmtconvert returned value to GMT? (default: false)
Returns
truncated julian date in the current timezone / in GMT depending on the gmt parameter

◆ getUnixDate()

time_t mio::Date::getUnixDate ( ) const

Return Unix time (or POSIX time). The Unix time is defined as the number of seconds since 1970-01-01T00:00 UTC (Unix Epoch). It is therefore ALWAYS in GMT. (defined as IEEE P1003.1 POSIX. See http://www.mail-archive.com/leapsecs@rom.usno.navy.mil/msg00109.html for some technical, historical and funny insight into the standardization process)

Returns
Unix time in the current timezone / in GMT depending on the gmt parameter

◆ getYear()

int mio::Date::getYear ( const bool &  gmt = false) const

Return year.

Parameters
gmtconvert returned value to GMT? (default: false)
Returns
year

◆ GMTToLocal()

double mio::Date::GMTToLocal ( const double &  in_gmt_julian) const
protected

◆ initStaticData()

bool mio::Date::initStaticData ( )
staticprotected

initialize the static map TZAbbrev

◆ isLeapYear() [1/2]

bool mio::Date::isLeapYear ( ) const

Return true if the current year is a leap year.

Returns
true if the current year is a leap year

◆ isLeapYear() [2/2]

bool mio::Date::isLeapYear ( const int &  i_year)
staticprotected

◆ isUndef()

bool mio::Date::isUndef ( ) const
inline

◆ localToGMT()

double mio::Date::localToGMT ( const double &  in_julian) const
protected

◆ mod() [1/2]

unsigned int mio::Date::mod ( const Date indate,
const unsigned int &  seconds 
)
static

Modulus of a date by a given number of seconds. This returns the modulus (in seconds) of a given date by the given number of seconds.

Parameters
[in]indateinput date
[in]secondsperiod (in seconds)
Returns
modulus in seconds

◆ mod() [2/2]

unsigned int mio::Date::mod ( const double &  julian,
const unsigned int &  seconds 
)
static

Modulus of a julian date by a given number of seconds. This returns the modulus (in seconds) of a given date by the given number of seconds.

Parameters
[in]julianinput date
[in]secondsperiod (in seconds)
Returns
modulus in seconds

◆ operator!=()

bool mio::Date::operator!= ( const Date indate) const

◆ operator*()

const Date mio::Date::operator* ( const double &  value) const

◆ operator*=()

Date & mio::Date::operator*= ( const double &  value)

◆ operator+() [1/2]

const Date mio::Date::operator+ ( const Date indate) const

◆ operator+() [2/2]

const Date mio::Date::operator+ ( const double &  indate) const

◆ operator+=() [1/2]

Date & mio::Date::operator+= ( const Date indate)

Intervals arithmetic Can be used to add an interval to an existing Date object. For example, you can add 1 day to a Date object dt simply with dt += 1.0. Please use the Duration type instead of Date for such calculations!

◆ operator+=() [2/2]

Date & mio::Date::operator+= ( const double &  indate)

◆ operator-() [1/2]

const Date mio::Date::operator- ( const Date indate) const

◆ operator-() [2/2]

const Date mio::Date::operator- ( const double &  indate) const

◆ operator-=() [1/2]

Date & mio::Date::operator-= ( const Date indate)

◆ operator-=() [2/2]

Date & mio::Date::operator-= ( const double &  indate)

◆ operator/()

const Date mio::Date::operator/ ( const double &  value) const

◆ operator/=()

Date & mio::Date::operator/= ( const double &  value)

◆ operator<()

bool mio::Date::operator< ( const Date indate) const

◆ operator<=()

bool mio::Date::operator<= ( const Date indate) const

◆ operator==()

bool mio::Date::operator== ( const Date indate) const

◆ operator>()

bool mio::Date::operator> ( const Date indate) const

◆ operator>=()

bool mio::Date::operator>= ( const Date indate) const

◆ parseTimeZone()

double mio::Date::parseTimeZone ( const std::string &  timezone_iso)
static

Parse an ISO 8601 formatted time zone specification. Time zones MUST be specified right after a date/time/combined representation according to the following formats:

  • 'Z' like in 2013-02-13T19:43Z, meaning GMT
  • '+01' like in 2013-02-13T20:43+01 meaning GMT+1
  • '+0130' like in 2013-02-13T21:13+0130 meaning GMT+1.5
  • '+01:30' like in 2013-02-13T21:13+01:30 meaning GMT+1.5
  • '-0515' like in 2013-02-13T15:28-0515 meaning GMT-5.25 See https://en.wikipedia.org/wiki/ISO_8601 for more information
    Parameters
    timezone_isotime zone string
    Returns
    time zone/shift in hours

◆ plausibilityCheck()

void mio::Date::plausibilityCheck ( const int &  in_year,
const int &  in_month,
const int &  in_day,
const int &  in_hour,
const int &  in_minute,
const double &  in_second 
)
staticprotected

◆ printFractionalDay()

std::string mio::Date::printFractionalDay ( const double &  fractional)
static

Nicely format an hour given as fractional day into a human readable hour.

Parameters
fractionalfractional day (ie: fractional part of a julian date)
Returns
string containing a human readable time

◆ rnd() [1/3]

const Date mio::Date::rnd ( const Date indate,
const double &  precision,
const RND type = CLOSEST 
)
static

◆ rnd() [2/3]

double mio::Date::rnd ( const double &  julian,
const double &  precision,
const RND type = CLOSEST 
)
static

Round a julian date to a given precision. If you want to round a local date, do NOT provide it as gmt julian but as local julian, otherwise things like rounding to the next day would be shifted by TimeZone.

Parameters
juliandate to round
precisionround date to the given precision, in seconds
typerounding strategy (default: CLOSEST)
Returns
rounded date

◆ rnd() [3/3]

void mio::Date::rnd ( const double &  precision,
const RND type = CLOSEST 
)

Round date to a given precision.

Parameters
precisionround date to the given precision, in seconds
typerounding strategy (default: CLOSEST)

◆ setDate() [1/10]

void mio::Date::setDate ( const Date in_date)

Copy setter.

Parameters
in_dateDate object to copy

◆ setDate() [2/10]

void mio::Date::setDate ( const double &  julian_in,
const double &  in_timezone 
)

Set date from a julian date (JD).

Parameters
julian_injulian date to set
in_timezonetimezone as an offset to GMT (in hours, optional)

◆ setDate() [3/10]

void mio::Date::setDate ( const int &  year,
const double &  jdn,
const double &  in_timezone 
)

Set date from a year and Julian Day Number (JDN).

Parameters
yearyear to set
jdnJulian Day Number within the provided year (1 to 365/366), starting at 00:00
in_timezonetimezone as an offset to GMT (in hours, optional)

◆ setDate() [4/10]

void mio::Date::setDate ( const int &  i_year,
const int &  i_month,
const int &  i_day,
const int &  i_hour,
const int &  i_minute,
const double &  i_timezone 
)

Set date by elements. All values are checked for plausibility.

Parameters
i_yearin 4 digits
i_monthplease keep in mind that first month of the year is 1 (ie: not 0!)
i_dayplease keep in mind that first day of the month is 1 (ie: not 0!)
i_hour
i_minute
i_timezonetimezone as an offset to GMT (in hours, optional)

◆ setDate() [5/10]

void mio::Date::setDate ( const int &  i_year,
const int &  i_month,
const int &  i_day,
const int &  i_hour,
const int &  i_minute,
const double &  i_second,
const double &  i_timezone 
)

Set date by elements. All values are checked for plausibility.

Parameters
i_yearin 4 digits
i_monthplease keep in mind that first month of the year is 1 (ie: not 0!)
i_dayplease keep in mind that first day of the month is 1 (ie: not 0!)
i_hour
i_minute
i_second
i_timezonetimezone as an offset to GMT (in hours, optional)

◆ setDate() [6/10]

void mio::Date::setDate ( const int &  i_year,
const int &  i_month,
const int &  i_day,
const int &  i_hour,
const int &  i_minute,
const int &  i_second,
const double &  i_timezone 
)

Set date by elements. All values are checked for plausibility.

Parameters
i_yearin 4 digits
i_monthplease keep in mind that first month of the year is 1 (ie: not 0!)
i_dayplease keep in mind that first day of the month is 1 (ie: not 0!)
i_hour
i_minute
i_second
i_timezonetimezone as an offset to GMT (in hours, optional)

◆ setDate() [7/10]

void mio::Date::setDate ( const int &  year,
const unsigned int &  month,
const unsigned int &  day,
const unsigned int &  hour,
const unsigned int &  minute,
const double &  in_timezone 
)

◆ setDate() [8/10]

void mio::Date::setDate ( const int &  year,
const unsigned int &  month,
const unsigned int &  day,
const unsigned int &  hour,
const unsigned int &  minute,
const double &  second,
const double &  in_timezone 
)

◆ setDate() [9/10]

void mio::Date::setDate ( const int &  year,
const unsigned int &  month,
const unsigned int &  day,
const unsigned int &  hour,
const unsigned int &  minute,
const unsigned int &  second,
const double &  in_timezone 
)

◆ setDate() [10/10]

void mio::Date::setDate ( const time_t &  i_time)

Set date from a Unix date.

Parameters
i_timeunix time (ie: as number of seconds since Unix Epoch, assumed to always be UTC+0)

◆ setExcelDate()

void mio::Date::setExcelDate ( const double  excel_in,
const double &  i_timezone 
)

Set date from an Excel date.

Parameters
excel_inExcel date to set
i_timezonetimezone as an offset to GMT (in hours, optional)

◆ setFromSys()

void mio::Date::setFromSys ( )

Set internal gmt time from system time as well as system time zone.

◆ setMatlabDate()

void mio::Date::setMatlabDate ( const double  matlab_in,
const double &  i_timezone 
)

Set date from an Matlab date.

Parameters
matlab_inMatlab date to set
i_timezonetimezone as an offset to GMT (in hours, optional)

◆ setModifiedJulianDate()

void mio::Date::setModifiedJulianDate ( const double &  julian_in,
const double &  i_timezone 
)

Set date from a modified julian date (MJD).

Parameters
julian_injulian date to set
i_timezonetimezone as an offset to GMT (in hours, optional)

◆ setRFC868Date()

void mio::Date::setRFC868Date ( const double &  julian_in,
const double &  i_timezone 
)

Set date from an RFC868 date (time since 1900-01-01T00:00 GMT, valid until 2036).

Parameters
julian_injulian date to set
i_timezonetimezone as an offset to GMT (in hours, optional)

◆ setTimeZone()

void mio::Date::setTimeZone ( const double &  in_timezone)

Set timezone and Daylight Saving Time flag.

Parameters
in_timezonetimezone as an offset to GMT (in hours)

◆ setUndef()

void mio::Date::setUndef ( const bool &  flag = true)

◆ setUnixDate()

void mio::Date::setUnixDate ( const time_t &  in_time)

Set date from a Unix date.

Parameters
in_timeunix time (ie: as number of seconds since Unix Epoch, always UTC)

◆ toString() [1/2]

const std::string mio::Date::toString ( ) const

◆ toString() [2/2]

const string mio::Date::toString ( const FORMATS type,
const bool &  gmt = false 
) const

Return a nicely formated string.

Parameters
typeselect the formating to apply (see the definition of Date::FORMATS)
gmtconvert returned value to GMT? (default: false)
Returns
formatted time in a string

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const Date date 
)
friend

◆ operator>>

std::istream& operator>> ( std::istream &  is,
Date date 
)
friend

Member Data Documentation

◆ __init

const bool mio::Date::__init = Date::initStaticData()
staticprotected

◆ daysLeapYear

const int mio::Date::daysLeapYear = {31,29,31,30,31,30,31,31,30,31,30,31}
staticprotected

◆ daysNonLeapYear

const int mio::Date::daysNonLeapYear = {31,28,31,30,31,30,31,31,30,31,30,31}
staticprotected

◆ DST_shift

const double mio::Date::DST_shift = 1.0
static

◆ epsilon

const double mio::Date::epsilon = epsilon_sec / (24.*3600.025)
static

minimum difference between two dates in days. 3600.025 is intentional to support high sampling rates

◆ epsilon_sec

const double mio::Date::epsilon_sec = 0.01
static

◆ Excel_offset

const double mio::Date::Excel_offset = 2415018.5
static

offset between julian date and Excel dates (note that excel invented some days...)

◆ gmt_julian

double mio::Date::gmt_julian
protected

◆ Matlab_offset

const double mio::Date::Matlab_offset = 1721058.5
static

offset between julian date and Matlab dates

◆ MJD_offset

const double mio::Date::MJD_offset = 2400000.5
static

offset between julian date and modified julian date

◆ RFC868_offset

const double mio::Date::RFC868_offset = 2415020.5
static

offset between julian date and RFC868 time (ref is 1900-01-01T00:00 GMT)

◆ timezone

double mio::Date::timezone
protected

◆ TZAbbrev

std::map< std::string, double > mio::Date::TZAbbrev
staticprotected

◆ undef

bool mio::Date::undef
protected

◆ Unix_offset

const double mio::Date::Unix_offset = 2440587.5
static

offset between julian date and Unix Epoch time


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