libdballe  9.11
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
dballe::Datetime Struct Reference

Date and time. More...

#include <types.h>

Public Member Functions

 Datetime ()
 Construct a missing datetime.
 
 Datetime (const Date &date, const Time &time)
 
 Datetime (int ye, int mo=1, int da=1, int ho=0, int mi=0, int se=0)
 Construct from broken down values. More...
 
void set_lower_bound ()
 Fill possibly missing fields with their lowest valid value.
 
void set_upper_bound ()
 Fill possibly missing fields with their highest valid value.
 
Date date () const
 Return a Date with this date.
 
Time time () const
 Return a Time with this time.
 
bool is_missing () const
 Check if this datetime is the missing value.
 
int to_julian () const
 Convert the date to Julian day.
 
int compare (const Datetime &other) const
 Generic comparison. More...
 
bool operator== (const Datetime &o) const
 
bool operator!= (const Datetime &o) const
 
bool operator< (const Datetime &o) const
 
bool operator> (const Datetime &o) const
 
bool operator<= (const Datetime &o) const
 
bool operator>= (const Datetime &o) const
 
int print_iso8601 (FILE *out, char sep='T', const char *end="\) const
 Print to an output stream in ISO8601 combined format.
 
int print (FILE *out, const char *end="\) const
 Print to an output stream in ISO8601 combined format.
 
void to_stream_iso8601 (std::ostream &out, char sep='T', const char *tz="") const
 Write the datetime to an output stream in ISO8601 combined format. More...
 
void to_csv_iso8601 (CSVWriter &out, char sep='T', const char *tz="") const
 Write the datetime as a CSV field in ISO8601 date format.
 
std::string to_string (char sep='T', const char *tz="") const
 Write to a string in ISO8601 combined format.
 

Static Public Member Functions

static Datetime from_julian (int jday, int ho=0, int mi=0, int se=0)
 Set the date from a Julian day.
 
static Datetime lower_bound (int ye, int mo, int da, int ho, int mi, int se)
 Return a Datetime filling the parts set to MISSING_INT with their lowest possible values.
 
static Datetime upper_bound (int ye, int mo, int da, int ho, int mi, int se)
 Return a Datetime filling the parts set to MISSING_INT with their highest possible values.
 
static Datetime from_iso8601 (const char *str)
 Parse an ISO8601 datetime string. More...
 
static void validate (int ye, int mo, int da, int ho, int mi, int se)
 Raise an exception if the three values do not represent a valid date/time. More...
 
static void normalise_h24 (int &ye, int &mo, int &da, int &ho, int &mi, int &se)
 Convert a datetime with an hour of 24:00:00 to hour 00:00:00 of the following day.
 

Public Attributes

unsigned short year
 
unsigned char month
 
unsigned char day
 
unsigned char hour
 
unsigned char minute
 
unsigned char second
 

Detailed Description

Date and time.

If year is 0xffff, then all the datetime is considered missing. Else, all fields must be set.

Constructor & Destructor Documentation

◆ Datetime()

dballe::Datetime::Datetime ( int  ye,
int  mo = 1,
int  da = 1,
int  ho = 0,
int  mi = 0,
int  se = 0 
)

Construct from broken down values.

A year of MISSING_INT constructs a missing Datetime. In any other case, arguments are validated with Datetime::validate().

Member Function Documentation

◆ compare()

int dballe::Datetime::compare ( const Datetime other) const

Generic comparison.

Returns a negative number if *this < other Returns zero if *this == other Returns a positive number if *this > other

◆ from_iso8601()

static Datetime dballe::Datetime::from_iso8601 ( const char *  str)
static

Parse an ISO8601 datetime string.

Both 'T' and ' ' are allowed as separators.

◆ to_stream_iso8601()

void dballe::Datetime::to_stream_iso8601 ( std::ostream &  out,
char  sep = 'T',
const char *  tz = "" 
) const

Write the datetime to an output stream in ISO8601 combined format.

Parameters
outthe output stream
septhe separator character between date and time
tzthe timezone string to use at the end of the datetime

◆ validate()

static void dballe::Datetime::validate ( int  ye,
int  mo,
int  da,
int  ho,
int  mi,
int  se 
)
static

Raise an exception if the three values do not represent a valid date/time.

A value of 23:59:60 is allowed to accomodate for times during leap seconds, but no effort is made to check if there has been a leap second on the given date.


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