Skip to content

calendar.h ~ calendar ~ timezone_type

Baptiste Thémine edited this page Oct 24, 2020 · 7 revisions
namespace calendar::timezone { typedef /* implementation defined */ timezone_type; }

Description

Defines integer type to store UTC time zone offset.

An ISO 8601 valid timezone_type is a signed (+ or -) integer containing 1 to 4 digits, 2 digits representing hour offset in a range from -18 to +18 followed by 2 digits representing minute offset which must equals 00, 15, 30 or 45. It can be safely handled as a utctz parameter such as in datetime_type or class Date constructor, otherwise the program is ill-formed.

For example :

  • +0, +100, -315, +1230, -945 are valid time zone offsets.
  • +1, +10, +123, +1234, -1900, +1900 are not valid time zone offsets.
  • -0500 is in octal base thus not a valid time zone offset.

Requirements

<ctime> is required to enable local time zone.

Member constants

Name Description
UTC Represents the zero or zulu UTC time zone.
LTZ Represents the local time zone of the machine, which equals to the current UTC time zone plus Daylight Saving Time.

Member functions

Name Description
operator+
operator-
Sets time zone offset.
operator>>
operator<<
I/O stream operators for calendar types.

Examples

In the following example, we display today's date in different time zones.

#include <iostream>
#include <JLC/JLC.h>
using namespace JLC;
using namespace calendar::timezone;

int main(){
    const Date today = Date::now();
    std::cout << "Local    = " << (today & LTZ) << std::endl;
    std::cout << "London   = " << (today & UTC) << std::endl;
    std::cout << "New York = " << (today & UTC-500) << std::endl;
    std::cout << "Tehran   = " << (today & UTC+330) << std::endl;
    std::cout << "Sydney   = " << (today & UTC+1000) << std::endl;
}
Local    = 2020-06-19T14:02:27+0200
London   = 2020-06-19T12:02:27+0000
New York = 2020-06-19T07:02:27-0500
Tehran   = 2020-06-19T15:32:27+0330
Sydney   = 2020-06-19T22:02:27+1000

See also

Clone this wiki locally