File: calendar.3

package info (click to toggle)
erlang-manpages 1%3A12.b.3-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,188 kB
  • ctags: 2
  • sloc: makefile: 68; perl: 30; sh: 15
file content (388 lines) | stat: -rw-r--r-- 9,054 bytes parent folder | download
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
.TH calendar 3 "stdlib  1.15.3" "Ericsson AB" "ERLANG MODULE DEFINITION"
.SH MODULE
calendar \- Local and universal time, day-of-the-week, date and time conversions
.SH DESCRIPTION
.LP
This module provides computation of local and universal time, day-of-the-week, and several time conversion functions\&.
.LP
Time is local when it is adjusted in accordance with the current time zone and daylight saving\&. Time is universal when it reflects the time at longitude zero, without any adjustment for daylight saving\&. Universal Coordinated Time (UTC) time is also called Greenwich Mean Time (GMT)\&.
.LP
The time functions \fIlocal_time/0\fR and \fIuniversal_time/0\fR provided in this module both return date and time\&. The reason for this is that separate functions for date and time may result in a date/time combination which is displaced by 24 hours\&. This happens if one of the functions is called before midnight, and the other after midnight\&. This problem also applies to the Erlang BIFs \fIdate/0\fR and \fItime/0\fR, and their use is strongly discouraged if a reliable date/time stamp is required\&.
.LP
All dates conform to the Gregorian calendar\&. This calendar was introduced by Pope Gregory XIII in 1582 and was used in all Catholic countries from this year\&. Protestant parts of Germany and the Netherlands adopted it in 1698, England followed in 1752, and Russia in 1918 (the October revolution of 1917 took place in November according to the Gregorian calendar)\&.
.LP
The Gregorian calendar in this module is extended back to year 0\&. For a given date, the \fIgregorian days\fR is the number of days up to and including the date specified\&. Similarly, the \fIgregorian seconds\fR for a given date and time, is the the number of seconds up to and including the specified date and time\&.
.LP
For computing differences between epochs in time, use the functions counting gregorian days or seconds\&. If epochs are given as local time, they must be converted to universal time, in order to get the correct value of the elapsed time between epochs\&. Use of the function \fItime_difference/2\fR is discouraged\&.

.SH DATA TYPES

.nf
date() = {Year, Month, Day}
  Year = int()
  Month = 1\&.\&.12
  Day = 1\&.\&.31
Year cannot be abbreviated\&. Example: 93 denotes year 93, not 1993\&.
Valid range depends on the underlying OS\&.
The date tuple must denote a valid date\&.

time() = {Hour, Minute, Second}
  Hour = 0\&.\&.23
  Minute = Second = 0\&.\&.59
.fi
.SH EXPORTS
.LP
.B
date_to_gregorian_days(Date) -> Days
.br
.B
date_to_gregorian_days(Year, Month, Day) -> Days
.br
.RS
.TP
Types
Date = date()
.br
Days = int()
.br
.RE
.RS
.LP
This function computes the number of gregorian days starting with year 0 and ending at the given date\&.
.RE
.LP
.B
datetime_to_gregorian_seconds({Date, Time}) -> Seconds
.br
.RS
.TP
Types
Date = date()
.br
Time = time()
.br
Seconds = int()
.br
.RE
.RS
.LP
This function computes the number of gregorian seconds starting with year 0 and ending at the given date and time\&.
.RE
.LP
.B
day_of_the_week(Date) -> DayNumber
.br
.B
day_of_the_week(Year, Month, Day) -> DayNumber
.br
.RS
.TP
Types
Date = date()
.br
DayNumber = 1\&.\&.7
.br
.RE
.RS
.LP
This function computes the day of the week given \fIYear\fR, \fIMonth\fR and \fIDay\fR\&. The return value denotes the day of the week as \fI1\fR: Monday, \fI2\fR: Tuesday, and so on\&.
.RE
.LP
.B
gregorian_days_to_date(Days) -> Date
.br
.RS
.TP
Types
Days = int()
.br
Date = date()
.br
.RE
.RS
.LP
This function computes the date given the number of gregorian days\&.
.RE
.LP
.B
gregorian_seconds_to_datetime(Seconds) -> {Date, Time}
.br
.RS
.TP
Types
Seconds = int()
.br
Date = date()
.br
Time = time()
.br
.RE
.RS
.LP
This function computes the date and time from the given number of gregorian seconds\&.
.RE
.LP
.B
is_leap_year(Year) -> bool()
.br
.RS
.LP
This function checks if a year is a leap year\&.
.RE
.LP
.B
last_day_of_the_month(Year, Month) -> int()
.br
.RS
.LP
This function computes the number of days in a month\&.
.RE
.LP
.B
local_time() -> {Date, Time}
.br
.RS
.TP
Types
Date = date()
.br
Time = time()
.br
.RE
.RS
.LP
This function returns the local time reported by the underlying operating system\&.
.RE
.LP
.B
local_time_to_universal_time({Date1, Time1}) -> {Date2, Time2}
.br
.RS
.LP
This function converts from local time to Universal Coordinated Time (UTC)\&. \fIDate1\fR must refer to a local date after Jan 1, 1970\&.
.SS Warning:
.LP
This function is deprecated\&. Use \fIlocal_time_to_universal_time_dst/1\fR instead, as it gives a more correct and complete result\&. Especially for the period that does not exist since it gets skipped during the switch \fIto\fR daylight saving time, this function still returns a result\&.

.RE
.LP
.B
local_time_to_universal_time_dst({Date1, Time1}) -> [{Date, Time}]
.br
.RS
.TP
Types
Date1 = Date = date()
.br
Time1 = Time = time()
.br
.RE
.RS
.LP
This function converts from local time to Universal Coordinated Time (UTC)\&. \fIDate1\fR must refer to a local date after Jan 1, 1970\&.
.LP
The return value is a list of 0, 1 or 2 possible UTC times:
.RS 2
.TP 4
.B
\fI[]\fR:
For a local \fI{Date1, Time1}\fR during the period that is skipped when switching \fIto\fR daylight saving time, there is no corresponding UTC since the local time is illegal - it has never happened\&.
.TP 4
.B
\fI[DstDateTimeUTC, DateTimeUTC]\fR:
For a local \fI{Date1, Time1}\fR during the period that is repeated when switching \fIfrom\fR daylight saving time, there are two corresponding UTCs\&. One for the first instance of the period when daylight saving time is still active, and one for the second instance\&.
.TP 4
.B
\fI[DateTimeUTC]\fR:
For all other local times there is only one corresponding UTC\&.
.RE
.RE
.LP
.B
now_to_local_time(Now) -> {Date, Time}
.br
.RS
.TP
Types
Now -- see erlang:now/0
.br
Date = date()
.br
Time = time()
.br
.RE
.RS
.LP
This function returns local date and time converted from the return value from \fIerlang:now()\fR\&.
.RE
.LP
.B
now_to_universal_time(Now) -> {Date, Time}
.br
.B
now_to_datetime(Now) -> {Date, Time}
.br
.RS
.TP
Types
Now -- see erlang:now/0
.br
Date = date()
.br
Time = time()
.br
.RE
.RS
.LP
This function returns Universal Coordinated Time (UTC) converted from the return value from \fIerlang:now()\fR\&.
.RE
.LP
.B
seconds_to_daystime(Seconds) -> {Days, Time}
.br
.RS
.TP
Types
Seconds = Days = int()
.br
Time = time()
.br
.RE
.RS
.LP
This function transforms a given number of seconds into days, hours, minutes, and seconds\&. The \fITime\fR part is always non-negative, but \fIDays\fR is negative if the argument \fISeconds\fR is\&.
.RE
.LP
.B
seconds_to_time(Seconds) -> Time
.br
.RS
.TP
Types
Seconds = int() < 86400
.br
Time = time()
.br
.RE
.RS
.LP
This function computes the time from the given number of seconds\&. \fISeconds\fR must be less than the number of seconds per day (86400)\&.
.RE
.LP
.B
time_difference(T1, T2) -> {Days, Time}
.br
.RS
.LP
This function returns the difference between two \fI{Date, Time}\fR tuples\&. \fIT2\fR should refer to an epoch later than \fIT1\fR\&.
.SS Warning:
.LP
This function is obsolete\&. Use the conversion functions for gregorian days and seconds instead\&.

.RE
.LP
.B
time_to_seconds(Time) -> Seconds
.br
.RS
.TP
Types
Time = time()
.br
Seconds = int()
.br
.RE
.RS
.LP
This function computes the number of seconds since midnight up to the specified time\&.
.RE
.LP
.B
universal_time() -> {Date, Time}
.br
.RS
.TP
Types
Date = date()
.br
Time = time()
.br
.RE
.RS
.LP
This function returns the Universal Coordinated Time (UTC) reported by the underlying operating system\&. Local time is returned if universal time is not available\&.
.RE
.LP
.B
universal_time_to_local_time({Date1, Time1}) -> {Date2, Time2}
.br
.RS
.TP
Types
Date1 = Date2 = date()
.br
Time1 = Time2 = time()
.br
.RE
.RS
.LP
This function converts from Universal Coordinated Time (UTC) to local time\&. \fIDate1\fR must refer to a date after Jan 1, 1970\&.
.RE
.LP
.B
valid_date(Date) -> bool()
.br
.B
valid_date(Year, Month, Day) -> bool()
.br
.RS
.TP
Types
Date = date()
.br
.RE
.RS
.LP
This function checks if a date is a valid\&.
.RE
.SH LEAP YEARS
.LP
The notion that every fourth year is a leap year is not completely true\&. By the Gregorian rule, a year Y is a leap year if either of the following rules is valid:
.RS 2
.TP 2
*
Y is divisible by 4, but not by 100; or
.TP 2
*
Y is divisible by 400\&.
.RE
.LP
Accordingly, 1996 is a leap year, 1900 is not, but 2000 is\&.
.SH DATE AND TIME SOURCE
.LP
Local time is obtained from the Erlang BIF \fIlocaltime/0\fR\&. Universal time is computed from the BIF \fIuniversaltime/0\fR\&.
.LP
The following facts apply:
.RS 2
.TP 2
*
there are 86400 seconds in a day
.TP 2
*
there are 365 days in an ordinary year
.TP 2
*
there are 366 days in a leap year
.TP 2
*
there are 1461 days in a 4 year period
.TP 2
*
there are 36524 days in a 100 year period
.TP 2
*
there are 146097 days in a 400 year period
.TP 2
*
there are 719528 days between Jan 1, 0 and Jan 1, 1970\&.
.RE