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, UTCOffset offset)
 
 LocalTime (std::string s)
 
 LocalTime (int year, int month, int day, int hour, int minute, UTCOffset offset)
 
std::string as_string (bool with_millisecond=false, bool with_timezone=true) 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
 
int millisecond () const
 
void set_day (int d)
 
void set_month (int m)
 
void set_year (int y)
 
void set_offset (UTCOffset offset)
 
void add_days (int d)
 
void add_months (int a)
 
void add_minutes (int a)
 
void add (boost::posix_time::time_duration duration)
 
bool operator== (LocalTime const &other) const
 
bool operator!= (LocalTime const &other) const
 
bool operator< (LocalTime const &other) const
 
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 ()
 
dcp::LocalTime as_utc () const
 

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)
 
UTCOffset _offset
 

Friends

struct ::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

Note that operator== for this class will return true for times that have different offsets but are the same actual time.

Definition at line 67 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,
UTCOffset  offset 
)

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

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 125 of file local_time.cc.

Member Function Documentation

◆ as_string()

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

Definition at line 188 of file local_time.cc.

◆ date()

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

Definition at line 211 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 115 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 220 of file local_time.cc.


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