-
Notifications
You must be signed in to change notification settings - Fork 1
/
osstzprs.h
71 lines (59 loc) · 2.48 KB
/
osstzprs.h
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
/* Copyright (c) 2012 by Michael J. Roberts. All Rights Reserved. */
/*
Name
osstzprs.h - portable POSIX-style "TZ" variable parser
Function
This routine parses a POSIX-style "TZ" variable, filling in an
os_tzinfo_t structure for os_get_timezone_info(). This is a portable
routine designed as a helper for implementing os_get_timezone_info() on
platforms where POSIX TZ strings can be used. Many Unix platforms use this
convention.
We parse the following formats:
EST5 - time zone with standard time only, no daylight time
EST5EDT - standard plus daylight time, with implied 1:00 daylight offset
EST5EDT4 - standard plus daylight time, with explicit daylight offset
EST5:00 - offset can include minutes
EST5:00:00 - ...and seconds
EST5EDT,M3.2.0,M11.1.0 - adds rules for daylight time start/stop dates
This isn't a full drop-in replacement for os_get_timezone_info(), since
(a) we don't want to assume that the Unix getenv() API is the way (or the
only way) to get the string to parse, and (b) some platforms that use the
TZ format might also accept other formats or have other ways of setting
the timezone. For Unix-type platforms platforms that don't need to check
for other syntax, this should be all you need to do to implement
os_get_timezone_info():
#include "osstzprs.h"
int os_get_timezone_info(struct os_tzinfo_t *info)
{
const char *tz = getenv("TZ");
return tz != 0 ? oss_parse_posix_tz(info, tz, strlen(tz), TRUE) : FALSE;
}
Notes
Modified
02/13/12 MJRoberts - Creation
*/
#ifndef OSSTZPRS_H
#define OSSTZPRS_H
#include "os.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Parse a string using the syntax of the POSIX "TZ" environment variable.
* If successful, fills in *info and returns true; if the string isn't in
* one of the recognized formats, returns false.
*
* 'west_is_positive' says whether UTC offsets are positive or negative to
* the west. The POSIX TZ convention is that west is positive, as in
* EST5EDT (New York time, 5 hours west of UTC), so this should be set to
* TRUE if the source material actually comes from a TZ variable. The
* reason we offer this option at all is that the zoneinfo database uses
* the opposite convention, where New York would be EST-5EDT.
*/
int oss_parse_posix_tz(struct os_tzinfo_t *info,
const char *tz, size_t len,
int west_is_positive);
#ifdef __cplusplus
}
#endif
#endif /* OSSTZPRS_H */