libdcp
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
dcp::LocalTime Class Reference

A representation of a local time (down to the second), including its offset from GMT (equivalent to xs:dateTime). More...

#include <local_time.h>

Public Member Functions

 LocalTime ()
 
 LocalTime (struct tm tm)
 
 LocalTime (boost::posix_time::ptime)
 
 LocalTime (boost::posix_time::ptime, int tz_hour, int tz_minute)
 
 LocalTime (std::string s)
 
std::string as_string (bool with_millisecond=false) const
 
std::string date () const
 
std::string time_of_day (bool with_second, bool with_millisecond) const
 
int day () const
 
int month () const
 
int year () const
 
int hour () const
 
int minute () const
 
int second () const
 
void set_year (int y)
 
void add_days (int d)
 
void add_months (int a)
 
void add_minutes (int a)
 
bool operator== (LocalTime const &other) const
 
bool operator!= (LocalTime const &other) const
 
bool operator< (LocalTime const &other) const
 

Static Public Member Functions

static LocalTime from_asn1_utc_time (std::string time)
 
static LocalTime from_asn1_generalized_time (std::string time)
 

Private Member Functions

void set (struct tm const *tm)
 
void set (boost::posix_time::ptime)
 
void set_local_time_zone ()
 

Private Attributes

int _year = 0
 year
 
int _month = 0
 month number of the year (1-12)
 
int _day = 0
 day number of the month (1-31)
 
int _hour = 0
 hour number of the day (0-23)
 
int _minute = 0
 minute number of the hour (0-59)
 
int _second = 0
 second number of the minute (0-59)
 
int _millisecond = 0
 millisecond number of the second (0-999)
 
int _tz_hour = 0
 hours by which this time is offset from UTC; can be negative
 
int _tz_minute = 0
 

Friends

class ::local_time_basic_test
 

Detailed Description

A representation of a local time (down to the second), including its offset from GMT (equivalent to xs:dateTime).

I tried to use boost for this, really I did, but I could not get it to parse strings of the required format (those that include time zones).

See http://www.w3.org/TR/xmlschema-2/#dateTime

Definition at line 63 of file local_time.h.

Constructor & Destructor Documentation

◆ LocalTime() [1/4]

LocalTime::LocalTime ( )

Construct a LocalTime from the current time

Definition at line 56 of file local_time.cc.

◆ LocalTime() [2/4]

LocalTime::LocalTime ( boost::posix_time::ptime  t)
explicit

Construct a LocalTime from a boost::posix_time::ptime using the local time zone

Definition at line 85 of file local_time.cc.

◆ LocalTime() [3/4]

LocalTime::LocalTime ( boost::posix_time::ptime  t,
int  tz_hour,
int  tz_minute 
)

Construct a LocalTime from a boost::posix_time::ptime and a time zone offset

Parameters
tz_minuteOffset from UTC in minutes; if the timezone is behind UTC this may be negative, e.g. -04:30 would have tz_hour=-1 and tz_minute=-30.

Definition at line 106 of file local_time.cc.

◆ LocalTime() [4/4]

LocalTime::LocalTime ( std::string  s)
explicit
Parameters
sA string of the form 2013-01-05T18:06:59[.123][+04:00]

Definition at line 127 of file local_time.cc.

Member Function Documentation

◆ as_string()

string LocalTime::as_string ( bool  with_millisecond = false) const
Returns
A string of the form 2013-01-05T18:06:59+04:00 or 2013-01-05T18:06:59.123+04:00

Definition at line 186 of file local_time.cc.

◆ date()

string LocalTime::date ( ) const
Returns
The date in the form YYYY-MM-DD

Definition at line 199 of file local_time.cc.

◆ set_local_time_zone()

void LocalTime::set_local_time_zone ( )
private

Set our UTC offset to be according to the local time zone

Definition at line 116 of file local_time.cc.

◆ time_of_day()

string LocalTime::time_of_day ( bool  with_second,
bool  with_millisecond 
) const
Returns
The time in the form HH:MM:SS or HH:MM:SS.mmm

Definition at line 208 of file local_time.cc.

Member Data Documentation

◆ _tz_minute

int dcp::LocalTime::_tz_minute = 0
private

Minutes by which this time is offset from UTC; if _tz_hour is negative this will be either 0 or negative.

Definition at line 153 of file local_time.h.


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