forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate.h
More file actions
158 lines (135 loc) · 4.64 KB
/
date.h
File metadata and controls
158 lines (135 loc) · 4.64 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* Copyright (C) 2003-2013 Runtime Revolution Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode 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 LiveCode. If not see <http://www.gnu.org/licenses/>. */
#ifndef __DATETIME__
#define __DATETIME__
struct MCDateTime
{
int4 year;
int4 month;
int4 day;
int4 hour;
int4 minute;
int4 second;
int4 bias;
};
#define DATETIME_ITEM_YEAR (1 << 0)
#define DATETIME_ITEM_MONTH (1 << 1)
#define DATETIME_ITEM_DAY (1 << 2)
#define DATETIME_ITEM_HOUR (1 << 3)
#define DATETIME_ITEM_MINUTE (1 << 4)
#define DATETIME_ITEM_SECOND (1 << 5)
#define DATETIME_ITEM_DATE (DATETIME_ITEM_YEAR | DATETIME_ITEM_MONTH | DATETIME_ITEM_DAY)
#define DATETIME_ITEM_TIME (DATETIME_ITEM_HOUR | DATETIME_ITEM_MINUTE | DATETIME_ITEM_SECOND)
// We need to support the following rules:
// 1) Day of month - (month, day)
// 2) Day of week in month:
// (month, day of week, day index)
// e.g. last Sunday in the month (month, SUNDAY, -1)
// second Monday in the month (month, MONDAY, 2)
// 3) Day of week after day:
// (month, day of week, day)
// e.g. first Sunday on/after the 8th (month, SUNDAY, 8)
// 4) Day of week before day:
// (month, day of week, day)
// e.g. last Sunday on/before the 25th (month, SUNDAY, 25)
//
// We also need the time at which the switch happens - this can
// be WALL_TIME, STANDARD_TIME or UTC_TIME.
//
// Month is in range (0-12)
// Day of week is in range (0-7)
// Day index is in range (-5..5)
// Day is in range (0-31)
//
// Therefore we could (in theory) store an entire rule in 16-bits:
// 2 bits for rule type
// 4 bits for month
// 3 bits for day of week
// 5 bits for day or day index
// 2 bits for time mode
// 16 bits for time offset
// (although this limits the precision of the time offset)
//
// This is useful to note for encoding and storage of time zone
// DST rules - but when in a locale structure we want speed
// so we will store them unpacked - which needs 8 bytes per
// rule, plus 8 bytes to store the year range.
#define DATETIME_ZONE_TIME_WALL 0
#define DATETIME_ZONE_TIME_STANDARD 1
#define DATETIME_ZONE_TIME_UTC 2
#define DATETIME_ZONE_RULE_DAY_OF_MONTH (0 << 4)
#define DATETIME_ZONE_RULE_DAY_OF_WEEK (1 << 4)
#define DATETIME_ZONE_RULE_DAY_OF_WEEK_AFTER (2 << 4)
#define DATETIME_ZONE_RULE_DAY_OF_WEEK_BEFORE (3 << 4)
struct MCDateTimeZoneDSTRuleEntry
{
int1 flags;
int1 month;
int1 day;
int1 weekday;
int4 time;
};
struct MCDateTimeZoneDSTRule
{
int4 start_year;
int4 finish_year;
int4 bias;
MCDateTimeZoneDSTRuleEntry start;
MCDateTimeZoneDSTRuleEntry finish;
};
struct MCDateTimeZone
{
int4 bias;
uint4 dst_rule_count;
MCDateTimeZoneDSTRule *dst_rules;
};
struct MCDateTimeLocale
{
const char *weekday_names[7];
const char *abbrev_weekday_names[7];
const char *month_names[12];
const char *abbrev_month_names[12];
const char *date_formats[3];
const char *time_formats[2];
const char *time24_formats[2];
const char *time_morning_suffix;
const char *time_evening_suffix;
};
typedef uint4 MCDateTimeFormat;
enum
{
DATETIME_FORMAT_NONE,
DATETIME_FORMAT_ITEMS,
DATETIME_FORMAT_MIME,
DATETIME_FORMAT_SHORT_ENGLISH_DATE,
DATETIME_FORMAT_ABBREV_ENGLISH_DATE,
DATETIME_FORMAT_LONG_ENGLISH_DATE,
DATETIME_FORMAT_SHORT_ENGLISH_TIME,
DATETIME_FORMAT_LONG_ENGLISH_TIME,
DATETIME_FORMAT_SHORT_ENGLISH_TIME24,
DATETIME_FORMAT_LONG_ENGLISH_TIME24,
DATETIME_FORMAT_SHORT_SYSTEM_DATE,
DATETIME_FORMAT_ABBREV_SYSTEM_DATE,
DATETIME_FORMAT_LONG_SYSTEM_DATE,
DATETIME_FORMAT_SHORT_SYSTEM_TIME,
DATETIME_FORMAT_LONG_SYSTEM_TIME
};
extern void MCD_date(Properties length, MCExecPoint &);
extern void MCD_time(Properties length, MCExecPoint &);
extern void MCD_monthnames(Properties length, MCExecPoint &ep);
extern void MCD_weekdaynames(Properties length, MCExecPoint &ep);
extern void MCD_dateformat(Properties length, MCExecPoint &ep);
extern Boolean MCD_convert(MCExecPoint &, Convert_form f, Convert_form fs, Convert_form p, Convert_form s);
extern bool MCD_convert_to_datetime(MCExecPoint &ep, Convert_form p_primary_from, Convert_form p_secondary_from, MCDateTime &r_datetime);
extern bool MCD_convert_from_datetime(MCExecPoint &ep, Convert_form p_primary_to, Convert_form p_secondary_to, MCDateTime &p_datetime);
extern void MCD_getlocaleformats();
#endif