summaryrefslogtreecommitdiffstats
path: root/pickles/tzif.pk
blob: 3f6edc24e80b7fd0abd6a6174e90b068668f5f53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* tzif.pk - Timezone Information Format (TZif) - RFC 8536 */

/* Work in progress */

/* Copyright (C) 2022 The poke authors */

/* This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* Ref: https://datatracker.ietf.org/doc/html/rfc8536 */
/* Ref: tzfile(5) */

/* set_endian(ENDIAN_BIG); */

/* Abbreviations
 *
 *   UT    Universal Time
 *   DST   Daylight Saving Time
 */

type TZif_Header = struct
  {
    char[4] magic == ['T', 'Z', 'i', 'f'];
    char ver : ver in [0UB, '2', '3', '4']; /* version */
    byte[15];

    /* number of UT/local indicators contained in the data block */
    uint32 isutcnt;

    /* number of standard/wall indicators contained in the data block */
    uint32 isstdcnt;

    /* number of leap-second records contained in the data block */
    uint32 leapcnt;

    /* number of transition times contained in the data block */
    uint32 timecnt;

    /* number of local time type records contained in the data block */
    uint32 typecnt : typecnt != 0 && (isutcnt == 0 || isutcnt == typecnt);

    /* number of octets used by the set of time zone designations contained
       in the data block. The count includes the trailing NUL (0x00) octet
       at the end of the last time zone designation */
    offset<uint32,B> charcnt : charcnt != 0#B;
  };

assert ((TZif_Header { typecnt = 1, charcnt = 1#B})'size == 44#B);

type TZif_Bool = struct byte
  {
    uint<7>;
    uint<1> value;
  };

type TZif_LocalTime = struct
  {
    /* UT offset: number of seconds to be added to UT in order to determine
       local time  */
    int32 utoff;

    /* is DST (Daylight Saving Time)? */
    TZif_Bool isdst;

    /* Designation index: A one-octet unsigned integer specifying
       a zero-based index into the series of time zone designation octets  */
    offset<byte,B> desigidx;
  };

type TZif_LeapSecond1 = struct
  {
    /* occur(rence): UNIX leap time value specifying the time at which a
       leap-second correction occurs  */
    uint32 occur;

    /* corr(ection): value of LEAPCORR on or after the occurrence  */
    int32 corr;
  };

type TZif_LeapSecond = struct
  {
    uint64 occur;
    int32 corr;
  };

var TZif_WALL = TZif_Bool{ value=0 },
    TZif_STD = TZif_Bool{ value=0 };

var TZif_LOCAL = TZif_Bool{ value=0 },
    TZif_UT = TZif_Bool{ value=0 };

/* TZif version 1 */
type TZif1 = struct
  {
    TZif_Header hdr;

    int32[hdr.timecnt] transition_times;
    uint8[hdr.timecnt] transition_types;
    TZif_LocalTime[hdr.typecnt] local_time_type_records;
    string[hdr.charcnt] time_zone_designations;
    TZif_LeapSecond1 leap_second_records;
    TZif_Bool[hdr.isstdcnt] standard_wall_indicators;
    TZif_Bool[hdr.isutcnt] ut_local_indicators;
  };

type TZif_NonNewLine = struct
  {
    byte value : value != '\n';
  };

type TZif_Footer = struct
  {
    char nl1 == '\n';
    TZif_NonNewLine[] tz_string;
    char nl2 == '\n';
  };

/* TZif version 2+ */
type TZif = struct
  {
    TZif1 v1 : v1.hdr.ver in ['2', '3'];

    //int64[v1.hdr.timecnt] transition_times;
    //byte[v1.hdr.timecnt] transition_types;
    //TZif_LocalTime[v1.hdr.typecnt] local_time_type_records;
    //string[v1.hdr.charcnt] time_zone_designations;
    //TZif_LeapSecond leap_second_records;
    //byte[v1.hdr.isstdcnt] standard_wall_indicators;

    //TZif_Footer footer;
  };

Generated by cgit on ageinghacker.net.
I am Luca Saiu. If you have reason to request commit access to one of these repositories please contact me. You may also send me patches by email.