Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Stroika::Foundation::Time::Timezone Class Reference

#include <Timezone.h>

Public Member Functions

 Timezone ()=delete
 
nonvirtual String AsHHMM (const Date &date, const TimeOfDay &tod, bool insertColon) const
 
nonvirtual String AsRFC1123 (const Date &date, const TimeOfDay &tod) const
 
nonvirtual BiasInMinutesFromUTCType GetBiasInMinutesFromUTC (const Date &date, const TimeOfDay &tod) const
 
nonvirtual make_signed_t< time_t > GetBiasFromUTC (const Date &date, const TimeOfDay &tod) const
 
nonvirtual optional< bool > IsDaylightSavingsTime (const Date &date, const optional< TimeOfDay > &tod)
 
nonvirtual Characters::String ToString () const
 

Static Public Member Functions

static optional< TimezoneParseTimezoneOffsetString (const char *tzStr)
 

Static Public Attributes

static constexpr Traversal::Range< BiasInMinutesFromUTCType > kBiasInMinutesFromUTCTypeValidRange {-24 * 60, 24 * 60}
 
static const Timezone kUTC {TZ_::eUTC}
 
static const Timezone kLocalTime {TZ_::eLocalTime}
 
static const optional< TimezonekUnknown {nullopt}
 

Detailed Description

The Timezone class represents what one would think of as a timezone - mostly.

But - it only supports these timezones: o UTC o LocalTime () special - whatever timezone this computer is in o Fixed Offset from UTC (suitable for reading and writing ISO8601 times)

But it currently does NOT support the notion of timezone like American/NewYork (unless that happens to be localtime) That feature may be eventually added - http://stroika-bugs.sophists.com/browse/STK-636

See also
https://msdn.microsoft.com/en-us/library/system.timezone(v=vs.110).aspx
Note
Comparisons: static_assert (totally_ordered<Timezone>); o comparison of < not 100% intuitive, but unambiguous, so these can be compared (by numeric value of flags/offsets).

Definition at line 104 of file Timezone.h.

Constructor & Destructor Documentation

◆ Timezone()

Stroika::Foundation::Time::Timezone::Timezone ( )
delete

if ValidationStrategy is eAssert (DEFAULT if not specified)

Precondition
kBiasInMinutesFromUTCTypeValidRange.Contains (biasInMinutesFromUTC) else throws if out of range.

Member Function Documentation

◆ ParseTimezoneOffsetString()

optional< Timezone > Timezone::ParseTimezoneOffsetString ( const char *  tzStr)
static

Parse string of the form: [+-]?HHMM, or [+-]?HH:MM, so for example -0500 is Timezone (-5*60), or -04:00 would be Timezone (-4*60).

On empty string, return nullopt, but on ill-formed timezone offset string (including out of range), throw (even if the string is EST, or some such - this requires numeric offset).

This parse function ignores any bad data at the end of tzStr (perhaps future version will be optionally more picky).

Definition at line 75 of file Timezone.cpp.

◆ AsHHMM()

String Timezone::AsHHMM ( const Date date,
const TimeOfDay tod,
bool  insertColon 
) const

generate a string of the form: [+-]?HHMM, or [+-]?HH:MM, so for example -0500 is Timezone (-5*60), or -04:00 would be Timezone (-4*60).

Note
Date/Time required in case Timezone is 'localtime' to determine DST

Definition at line 138 of file Timezone.cpp.

◆ AsRFC1123()

String Timezone::AsRFC1123 ( const Date date,
const TimeOfDay tod 
) const
See also
https://tools.ietf.org/html/rfc822#section-5

Can generate "GMT" or AsHMM(false) above.

Note
Date/Time required in case Timezone is 'localtime' to determine DST
Aliases
AsRFC822 ()

Definition at line 146 of file Timezone.cpp.

◆ GetBiasInMinutesFromUTC()

Timezone::BiasInMinutesFromUTCType Timezone::GetBiasInMinutesFromUTC ( const Date date,
const TimeOfDay tod 
) const

Depending on the form of the timezone, the offset from UTC could depend on the date (cuz of daylight savings time)

This offset (number of minutes) - is added to a UTC time to get the time in that local timezone.

Postcondition
(kBiasInMinutesFromUTCTypeValidRange.Contains (fBiasInMinutesFromUTC_));

Definition at line 156 of file Timezone.cpp.

◆ GetBiasFromUTC()

make_signed_t< time_t > Stroika::Foundation::Time::Timezone::GetBiasFromUTC ( const Date date,
const TimeOfDay tod 
) const

Depending on the form of the timezone, the offset from UTC could depend on the date (cuz of daylight savings time)

This offset (number of seconds) - is added to a UTC time to get the time in that local timezone.

Definition at line 37 of file Timezone.inl.

◆ IsDaylightSavingsTime()

optional< bool > Timezone::IsDaylightSavingsTime ( const Date date,
const optional< TimeOfDay > &  tod 
)

For some kinds of timezones, there is no way to know (e.g. +4:00), but return true if known true, and false if known false.

Definition at line 175 of file Timezone.cpp.

◆ ToString()

Characters::String Timezone::ToString ( ) const
See also
Characters::ToString ();

Definition at line 186 of file Timezone.cpp.

Member Data Documentation

◆ kBiasInMinutesFromUTCTypeValidRange

constexpr Traversal::Range<BiasInMinutesFromUTCType> Stroika::Foundation::Time::Timezone::kBiasInMinutesFromUTCTypeValidRange {-24 * 60, 24 * 60}
staticconstexpr

According to https://en.wikipedia.org/wiki/List_of_UTC_time_offsets, these actually vary from -12, to 14. But logically, the only thing really crazy would be > 24 or < -24 hours.

Definition at line 120 of file Timezone.h.

◆ kUTC

constexpr Timezone Stroika::Foundation::Time::Timezone::kUTC {TZ_::eUTC}
staticconstexpr

Returns Timezone object in UTC timezone.

Definition at line 144 of file Timezone.h.

◆ kLocalTime

constexpr Timezone Stroika::Foundation::Time::Timezone::kLocalTime {TZ_::eLocalTime}
staticconstexpr

Returns Timezone object in localtime timezone.

Note
- LocalTime is a STICKY property. This does NOT return the FIXED OFFSET for the current local-time, but rather a special Timezone which always references that global current timezone.

Definition at line 153 of file Timezone.h.

◆ kUnknown

constexpr optional< Timezone > Stroika::Foundation::Time::Timezone::kUnknown {nullopt}
staticconstexpr

Returns Timezone object in localtime timezone.

Definition at line 159 of file Timezone.h.


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