Evo C++ Library v0.5.1
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
TimeZoneOffset Struct Reference

#include <evo/time.h>

Detailed Description

Structure holding a time zone offset from UTC.

Public Member Functions

 TimeZoneOffset ()
 Constructor to set as null (no time zone). More...
 
 TimeZoneOffset (int minutes)
 Constructor to initialize with a time zone offset in minutes. More...
 
 TimeZoneOffset (int hours, int hour_minutes)
 Constructor to initialize with a time zone offset from hours and minutes. More...
 
 TimeZoneOffset (const TimeZoneOffset &src)
 Copy constructor. More...
 
int compare (const TimeZoneOffset &oth) const
 Compare to another time zone offset. More...
 
template<class T >
T & format (T &out, char delim=':', bool allow_z=true) const
 Format timezone offset to String or Stream. More...
 
bool null () const
 Get whether time zone offset is null (not set). More...
 
bool operator!= (const TimeZoneOffset &oth) const
 Compare for inequality with another time of day. More...
 
bool operator< (const TimeZoneOffset &oth) const
 Compare whether less than another time of day. More...
 
bool operator<= (const TimeZoneOffset &oth) const
 Compare whether less than or equal to another time of day. More...
 
TimeZoneOffsetoperator= (const TimeZoneOffset &src)
 Assignment operator. More...
 
bool operator== (const TimeZoneOffset &oth) const
 Compare for equality with another time of day. More...
 
bool operator> (const TimeZoneOffset &oth) const
 Compare whether greater than another time of day. More...
 
bool operator>= (const TimeZoneOffset &oth) const
 Compare whether greater than or equal to another time of day. More...
 
bool parse (const SubString &str, bool required=false)
 Set timezone offset from parsing standard timezone offset string. More...
 
bool parse_std_impl (const char *&inp, const char *end, bool required=false)
 Set timezone offset from parsing standard timezone offset string (used internally). More...
 
void set ()
 Set as null (no time zone). More...
 
bool set (int new_minutes)
 Set to time zone offset in minutes. More...
 
bool set (int hours, int hour_minutes)
 Set new time zone offset from hours and minutes. More...
 
TimeZoneOffsetset_local ()
 Set to current time zone offset. More...
 
TimeZoneOffsetset_utc ()
 Set to UTC. More...
 
bool validate () const
 Validate current timezone offset. More...
 

Public Attributes

int minutes
 Time zone offset from UTC in minutes (-720 - 840), OFFSET_NULL for null, negative for the Western Hemisphere (America), positive for the remaining time zones. More...
 

Static Public Attributes

static const int OFFSET_MAX = 1439
 Maximum time zone offset in minutes (normally 840 but enforced at 1439) More...
 
static const int OFFSET_MIN = -1439
 Minimum time zone offset in minutes (normally -720 but enforced at -1439) More...
 
static const int OFFSET_NULL = Int::MIN
 Special value for null time zone (null is less than all other values), i.e. no assigned time zone. More...
 

Constructor & Destructor Documentation

◆ TimeZoneOffset() [1/4]

TimeZoneOffset ( )
inline

Constructor to set as null (no time zone).

◆ TimeZoneOffset() [2/4]

TimeZoneOffset ( int  minutes)
inline

Constructor to initialize with a time zone offset in minutes.

Parameters
minutesTime zone offset from UTC in minutes, 0 for UTC, negative for the Western Hemisphere (America), positive for the remaining time zones, OFFSET_NULL for null (no time zone)

◆ TimeZoneOffset() [3/4]

TimeZoneOffset ( int  hours,
int  hour_minutes 
)
inline

Constructor to initialize with a time zone offset from hours and minutes.

  • This does not validate the arguments – use validate() to validate
Parameters
hoursOffset hours (-23 - 23)
hour_minutesOffset minutes (0 - 59)

◆ TimeZoneOffset() [4/4]

TimeZoneOffset ( const TimeZoneOffset src)
inline

Copy constructor.

Parameters
srcSource to copy

Member Function Documentation

◆ compare()

int compare ( const TimeZoneOffset oth) const
inline

Compare to another time zone offset.

Parameters
othOther time zone to compare to
Returns
Result (<0 if this is less, 0 if equal, >0 if this is greater)

◆ format()

T& format ( T &  out,
char  delim = ':',
bool  allow_z = true 
) const
inline

Format timezone offset to String or Stream.

  • Syntax is based on ISO 8601:
    • Z if no offset and allow_z=true
    • +HH:MM – positive offset with default delimiter, other delimiters may be used but aren't considered standard
    • -HH:MM – negative offset with default delimiter, other delimiters may be used but aren't considered standard
    • +HHMM – positive offset without a delimiter
    • -HHMM – negative offset without a delimiter
Parameters
outOutput String/Stream to format to
delimDelimiter to use between fields, usually : or 0 for no delimiter – other values are non-standard
allow_zWhether to allow formatting as Z for UTC, false to use +00:00 instead (where : is delim)
Returns
Reference to out

◆ null()

bool null ( ) const
inline

Get whether time zone offset is null (not set).

Returns
Whether null

◆ operator!=()

bool operator!= ( const TimeZoneOffset oth) const
inline

Compare for inequality with another time of day.

Parameters
othOther time of day to compare to
Returns
Whether inequal

◆ operator<()

bool operator< ( const TimeZoneOffset oth) const
inline

Compare whether less than another time of day.

Parameters
othOther time of day to compare to
Returns
Whether less than

◆ operator<=()

bool operator<= ( const TimeZoneOffset oth) const
inline

Compare whether less than or equal to another time of day.

Parameters
othOther time of day to compare to
Returns
Whether less than or equal

◆ operator=()

TimeZoneOffset& operator= ( const TimeZoneOffset src)
inline

Assignment operator.

Parameters
srcSource to copy
Returns
This

◆ operator==()

bool operator== ( const TimeZoneOffset oth) const
inline

Compare for equality with another time of day.

Parameters
othOther time of day to compare to
Returns
Whether equal

◆ operator>()

bool operator> ( const TimeZoneOffset oth) const
inline

Compare whether greater than another time of day.

Parameters
othOther time of day to compare to
Returns
Whether greater than

◆ operator>=()

bool operator>= ( const TimeZoneOffset oth) const
inline

Compare whether greater than or equal to another time of day.

Parameters
othOther time of day to compare to
Returns
Whether greater than or equal

◆ parse()

bool parse ( const SubString str,
bool  required = false 
)
inline

Set timezone offset from parsing standard timezone offset string.

  • Supported timezone offset syntax is based on ISO 8601:
    • Z or z if no offset
    • +HH:MM or -HH:MM – offset with standard delimiter, other delimiters not supported
    • +HHMM or -HHMM – offset without a delimiter
    • +HH or -HH – offset with just hours
    • Sign is required with numeric offset
  • An empty time zone is treated as null if required=false, or an error if required=true
Parameters
strString to parse
requiredWhether a value is required, false if null is ok, true if null is an error
Returns
Whether successful, false on bad input or unrecognized format

◆ parse_std_impl()

bool parse_std_impl ( const char *&  inp,
const char *  end,
bool  required = false 
)
inline

Set timezone offset from parsing standard timezone offset string (used internally).

  • Supported timezone offset syntax is based on ISO 8601:
    • Z or z if no offset, same if empty or a non-digit character is found that doesn't match the syntax
    • +HH:MM or -HH:MM – offset with standard delimiter, other delimiters not supported
    • +HHMM or -HHMM – offset without a delimiter
    • +HH or -HH – offset with just hours
    • Sign is required with numeric offset
  • An empty time zone is treated as null if required=false, or an error if required=true
Parameters
inpStart parsing pointer (must be <= end), set to stop position [in/out]
endEnd of string pointer, must not be NULL
requiredWhether a value is required, false if null is ok, true if null is an error
Returns
Whether successful, false on bad input or unrecognized format or if no value while required=true

◆ set() [1/3]

void set ( )
inline

Set as null (no time zone).

◆ set() [2/3]

bool set ( int  new_minutes)
inline

Set to time zone offset in minutes.

Parameters
new_minutesTime zone offset from UTC in minutes, 0 for UTC, negative for the Western Hemisphere (America), positive for the remaining time zones, OFFSET_NULL for null (no time zone)
Returns
Whether successful, false if field is invalid

◆ set() [3/3]

bool set ( int  hours,
int  hour_minutes 
)
inline

Set new time zone offset from hours and minutes.

Parameters
hoursOffset hours (-23 - 23)
hour_minutesOffset minutes (0 - 59)
Returns
Whether successful, false if one of the fields is invalid

◆ set_local()

TimeZoneOffset& set_local ( )
inline

Set to current time zone offset.

  • If the system returns an error (time zone unknown or unavailable), this assumes UTC

◆ set_utc()

TimeZoneOffset& set_utc ( )
inline

Set to UTC.

◆ validate()

bool validate ( ) const
inline

Validate current timezone offset.

Returns
Whether timzone offset is valid, false if value is invalid (not null and out of range)

Member Data Documentation

◆ minutes

int minutes

Time zone offset from UTC in minutes (-720 - 840), OFFSET_NULL for null, negative for the Western Hemisphere (America), positive for the remaining time zones.

◆ OFFSET_MAX

const int OFFSET_MAX = 1439
static

Maximum time zone offset in minutes (normally 840 but enforced at 1439)

◆ OFFSET_MIN

const int OFFSET_MIN = -1439
static

Minimum time zone offset in minutes (normally -720 but enforced at -1439)

◆ OFFSET_NULL

const int OFFSET_NULL = Int::MIN
static

Special value for null time zone (null is less than all other values), i.e. no assigned time zone.


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