CppCommon  1.0.4.1
C++ Common Library
Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
CppCommon::Timezone Class Reference

Timezone. More...

#include <timezone.h>

Public Member Functions

 Timezone ()
 Initialize timezone with a current local timezone. More...
 
 Timezone (const std::string &name, const Timespan &offset, const Timespan &dstoffset=Timespan::zero())
 Initialize timezone with a given local time offset and daylight saving time offset. More...
 
 Timezone (const Timezone &)=default
 
 Timezone (Timezone &&)=default
 
 ~Timezone ()=default
 
Timezoneoperator= (const Timezone &)=default
 
Timezoneoperator= (Timezone &&)=default
 
const std::string & name () const noexcept
 Get timezone name. More...
 
const Timespanoffset () const noexcept
 Get timezone offset. More...
 
const Timespandaylight () const noexcept
 Get timezone daylight saving time offset. More...
 
Timespan total () const noexcept
 Get timezone total offset. More...
 
LocalTime Convert (const UtcTime &utctime) const
 Convert UTC time to local time using the current timezone. More...
 
UtcTime Convert (const LocalTime &localtime) const
 Convert local time to UTC time using the current timezone. More...
 
void swap (Timezone &timezone) noexcept
 Swap two instances. More...
 

Static Public Member Functions

static Timezone utc ()
 Get the UTC timezone (Greenwich Mean Time) More...
 
static Timezone local ()
 Get the local timezone. More...
 

Protected Attributes

std::string _name
 Timezone name. More...
 
Timespan _offset
 Timezone offset. More...
 
Timespan _dstoffset
 Timezone daylight saving time offset. More...
 

Friends

bool operator== (const Timezone &timezone1, const Timezone &timezone2) noexcept
 
bool operator!= (const Timezone &timezone1, const Timezone &timezone2) noexcept
 
bool operator> (const Timezone &timezone1, const Timezone &timezone2) noexcept
 
bool operator< (const Timezone &timezone1, const Timezone &timezone2) noexcept
 
bool operator>= (const Timezone &timezone1, const Timezone &timezone2) noexcept
 
bool operator<= (const Timezone &timezone1, const Timezone &timezone2) noexcept
 
void swap (Timezone &timezone1, Timezone &timezone2) noexcept
 

Detailed Description

Timezone.

Timezone wraps the current timezone and dynamic daylight saving time settings.

Not thread-safe.

Examples
time_timezone.cpp.

Definition at line 24 of file timezone.h.

Constructor & Destructor Documentation

◆ Timezone() [1/4]

CppCommon::Timezone::Timezone ( )

Initialize timezone with a current local timezone.

Definition at line 19 of file timezone.cpp.

◆ Timezone() [2/4]

CppCommon::Timezone::Timezone ( const std::string &  name,
const Timespan offset,
const Timespan dstoffset = Timespan::zero() 
)
inlineexplicit

Initialize timezone with a given local time offset and daylight saving time offset.

Parameters
name- Timezone name
offset- Local time offset
dstoffset- Daylight saving time offset (default is Timespan::zero())

Definition at line 35 of file timezone.h.

◆ Timezone() [3/4]

CppCommon::Timezone::Timezone ( const Timezone )
default

◆ Timezone() [4/4]

CppCommon::Timezone::Timezone ( Timezone &&  )
default

◆ ~Timezone()

CppCommon::Timezone::~Timezone ( )
default

Member Function Documentation

◆ Convert() [1/2]

UtcTime CppCommon::Timezone::Convert ( const LocalTime localtime) const
inline

Convert local time to UTC time using the current timezone.

Parameters
localtime- Local time
Returns
Local time

Definition at line 81 of file timezone.h.

◆ Convert() [2/2]

LocalTime CppCommon::Timezone::Convert ( const UtcTime utctime) const
inline

Convert UTC time to local time using the current timezone.

Parameters
utctime- UTC time
Returns
Local time

Definition at line 74 of file timezone.h.

◆ daylight()

const Timespan& CppCommon::Timezone::daylight ( ) const
inlinenoexcept

Get timezone daylight saving time offset.

Examples
time_timezone.cpp.

Definition at line 64 of file timezone.h.

◆ local()

static Timezone CppCommon::Timezone::local ( )
inlinestatic

Get the local timezone.

Thread-safe.

Returns
Local timezone
Examples
time_timezone.cpp.

Definition at line 99 of file timezone.h.

◆ name()

const std::string& CppCommon::Timezone::name ( ) const
inlinenoexcept

Get timezone name.

Examples
time_timezone.cpp.

Definition at line 60 of file timezone.h.

◆ offset()

const Timespan& CppCommon::Timezone::offset ( ) const
inlinenoexcept

Get timezone offset.

Examples
time_timezone.cpp.

Definition at line 62 of file timezone.h.

◆ operator=() [1/2]

Timezone& CppCommon::Timezone::operator= ( const Timezone )
default

◆ operator=() [2/2]

Timezone& CppCommon::Timezone::operator= ( Timezone &&  )
default

◆ swap()

void CppCommon::Timezone::swap ( Timezone timezone)
inlinenoexcept

Swap two instances.

Definition at line 11 of file timezone.inl.

◆ total()

Timespan CppCommon::Timezone::total ( ) const
inlinenoexcept

Get timezone total offset.

Definition at line 67 of file timezone.h.

◆ utc()

static Timezone CppCommon::Timezone::utc ( )
inlinestatic

Get the UTC timezone (Greenwich Mean Time)

Thread-safe.

Returns
UTC timezone
Examples
time_timezone.cpp.

Definition at line 90 of file timezone.h.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const Timezone timezone1,
const Timezone timezone2 
)
friend

Definition at line 48 of file timezone.h.

◆ operator<

bool operator< ( const Timezone timezone1,
const Timezone timezone2 
)
friend

Definition at line 52 of file timezone.h.

◆ operator<=

bool operator<= ( const Timezone timezone1,
const Timezone timezone2 
)
friend

Definition at line 56 of file timezone.h.

◆ operator==

bool operator== ( const Timezone timezone1,
const Timezone timezone2 
)
friend

Definition at line 46 of file timezone.h.

◆ operator>

bool operator> ( const Timezone timezone1,
const Timezone timezone2 
)
friend

Definition at line 50 of file timezone.h.

◆ operator>=

bool operator>= ( const Timezone timezone1,
const Timezone timezone2 
)
friend

Definition at line 54 of file timezone.h.

◆ swap

void swap ( Timezone timezone1,
Timezone timezone2 
)
friend

Definition at line 19 of file timezone.inl.

Member Data Documentation

◆ _dstoffset

Timespan CppCommon::Timezone::_dstoffset
protected

Timezone daylight saving time offset.

Definition at line 112 of file timezone.h.

◆ _name

std::string CppCommon::Timezone::_name
protected

Timezone name.

Definition at line 108 of file timezone.h.

◆ _offset

Timespan CppCommon::Timezone::_offset
protected

Timezone offset.

Definition at line 110 of file timezone.h.


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