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 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
<TITLE>calendar</TITLE>
<SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
<STYLE TYPE="text/css">
<!--
.REFBODY { margin-left: 13mm }
.REFTYPES { margin-left: 8mm }
-->
</STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
ALINK="#FF0000">
<!-- refpage -->
<CENTER>
<A HREF="http://www.erlang.se">
<IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif">
</A>
<H1>calendar</H1>
</CENTER>
<H3>MODULE</H3>
<DIV CLASS=REFBODY>
calendar
</DIV>
<H3>MODULE SUMMARY</H3>
<DIV CLASS=REFBODY>
Local and universal time, day-of-the-week, date and
time conversions
</DIV>
<H3>DESCRIPTION</H3>
<DIV CLASS=REFBODY>
<P>This module provides computation of local and universal time,
day-of-the-week, and several time conversion functions.
<P>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).
<P>The time functions <CODE>local_time/0</CODE> and
<CODE>universal_time/0</CODE> 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 <CODE>date/0</CODE> and <CODE>time/0</CODE>, and
their use is strongly discouraged if a reliable date/time stamp
is required.
<P>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).
<P>The Gregorian calendar in this module is extended back to year 0.
For a given date, the <STRONG>gregorian days</STRONG> is the number of
days up to and including the date specified. Similarly,
the <STRONG>gregorian seconds</STRONG> for a given date and time, is
the the number of seconds up to and including the specified date
and time.
<P>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 <CODE>time_difference/2</CODE> is discouraged.
</DIV>
<H3>DATA TYPES</H3>
<DIV CLASS=REFBODY>
<PRE>
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
</PRE>
</DIV>
<H3>EXPORTS</H3>
<P><A NAME="date_to_gregorian_days/1"><STRONG><CODE>date_to_gregorian_days(Date) -> Days</CODE></STRONG></A><BR>
<A NAME="date_to_gregorian_days/3"><STRONG><CODE>date_to_gregorian_days(Year, Month, Day) -> Days</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Date = date()</CODE></STRONG><BR>
<STRONG><CODE>Days = int()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This function computes the number of gregorian days starting
with year 0 and ending at the given date.
</DIV>
<P><A NAME="datetime_to_gregorian_seconds/2"><STRONG><CODE>datetime_to_gregorian_seconds({Date, Time}) -> Seconds
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Date = date()</CODE></STRONG><BR>
<STRONG><CODE>Time = time()</CODE></STRONG><BR>
<STRONG><CODE>Seconds = int()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This function computes the number of gregorian seconds
starting with year 0 and ending at the given date and time.
</DIV>
<P><A NAME="day_of_the_week/1"><STRONG><CODE>day_of_the_week(Date) -> DayNumber</CODE></STRONG></A><BR>
<A NAME="day_of_the_week/3"><STRONG><CODE>day_of_the_week(Year, Month, Day) -> DayNumber</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Date = date()</CODE></STRONG><BR>
<STRONG><CODE>DayNumber = 1..7</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This function computes the day of the week given <CODE>Year</CODE>,
<CODE>Month</CODE> and <CODE>Day</CODE>. The return value denotes the day
of the week as <CODE>1</CODE>: Monday, <CODE>2</CODE>: Tuesday, and so on.
</DIV>
<P><A NAME="gregorian_days_to_date/1"><STRONG><CODE>gregorian_days_to_date(Days) -> Date</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Days = int()</CODE></STRONG><BR>
<STRONG><CODE>Date = date()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This function computes the date given the number of
gregorian days.
</DIV>
<P><A NAME="gregorian_seconds_to_datetime/1"><STRONG><CODE>gregorian_seconds_to_datetime(Seconds) -> {Date, Time}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Seconds = int()</CODE></STRONG><BR>
<STRONG><CODE>Date = date()</CODE></STRONG><BR>
<STRONG><CODE>Time = time()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This function computes the date and time from the given
number of gregorian seconds.
</DIV>
<P><A NAME="is_leap_year/1"><STRONG><CODE>is_leap_year(Year) -> bool()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This function checks if a year is a leap year.
</DIV>
<P><A NAME="last_day_of_the_month/2"><STRONG><CODE>last_day_of_the_month(Year, Month) -> int()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This function computes the number of days in a month.
</DIV>
<P><A NAME="local_time/0"><STRONG><CODE>local_time() -> {Date, Time}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Date = date()</CODE></STRONG><BR>
<STRONG><CODE>Time = time()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This function returns the local time reported by
the underlying operating system.
</DIV>
<P><A NAME="local_time_to_universal_time/2"><STRONG><CODE>local_time_to_universal_time({Date1, Time1}) ->
{Date2, Time2}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This function converts from local time to Universal
Coordinated Time (UTC). <CODE>Date1</CODE> must refer to a local
date after Jan 1, 1970.
<P>
<TABLE CELLPADDING=4>
<TR>
<TD VALIGN=TOP><IMG ALT="Warning!" SRC="warning.gif"></TD>
<TD>
<P>This function is deprecated. Use
<CODE>local_time_to_universal_time_dst/1</CODE> 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 <STRONG>to</STRONG> daylight saving time, this function
still returns a result. </TD>
</TR>
</TABLE>
</DIV>
<P><A NAME="local_time_to_universal_time_dst/2"><STRONG><CODE>local_time_to_universal_time_dst({Date1, Time1}) ->
[{Date, Time}]</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Date1 = Date = date()</CODE></STRONG><BR>
<STRONG><CODE>Time1 = Time = time()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This function converts from local time to Universal
Coordinated Time (UTC). <CODE>Date1</CODE> must refer to a local
date after Jan 1, 1970.
<P>The return value is a list of 0, 1 or 2 possible UTC times:
<P>
<DL>
<DT>
<CODE>[]</CODE>
</DT>
<DD>
For a local <CODE>{Date1, Time1}</CODE> during the period that
is skipped when switching <STRONG>to</STRONG> daylight saving
time, there is no corresponding UTC since the local time
is illegal - it has never happened.<BR>
</DD>
<DT>
<CODE>[DstDateTimeUTC, DateTimeUTC]</CODE>
</DT>
<DD>
For a local <CODE>{Date1, Time1}</CODE> during the period that
is repeated when switching <STRONG>from</STRONG> 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.<BR>
</DD>
<DT>
<CODE>[DateTimeUTC]</CODE>
</DT>
<DD>
For all other local times there is only one
corresponding UTC.<BR>
</DD>
</DL>
</DIV>
<P><A NAME="now_to_local_time/1"><STRONG><CODE>now_to_local_time(Now) -> {Date, Time}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Now -- see erlang:now/0</CODE></STRONG><BR>
<STRONG><CODE>Date = date()</CODE></STRONG><BR>
<STRONG><CODE>Time = time()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This function returns local date and time converted from
the return value from <CODE>erlang:now()</CODE>.
</DIV>
<P><A NAME="now_to_universal_time/1"><STRONG><CODE>now_to_universal_time(Now) -> {Date, Time}</CODE></STRONG></A><BR>
<A NAME="now_to_datetime/1"><STRONG><CODE>now_to_datetime(Now) -> {Date, Time}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Now -- see erlang:now/0</CODE></STRONG><BR>
<STRONG><CODE>Date = date()</CODE></STRONG><BR>
<STRONG><CODE>Time = time()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This function returns Universal Coordinated Time (UTC)
converted from the return value from <CODE>erlang:now()</CODE>.
</DIV>
<P><A NAME="seconds_to_daystime/1"><STRONG><CODE>seconds_to_daystime(Seconds) -> {Days, Time}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Seconds = Days = int()</CODE></STRONG><BR>
<STRONG><CODE>Time = time()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This function transforms a given number of seconds into days,
hours, minutes, and seconds. The <CODE>Time</CODE> part is always
non-negative, but <CODE>Days</CODE> is negative if the argument
<CODE>Seconds</CODE> is.
</DIV>
<P><A NAME="seconds_to_time/1"><STRONG><CODE>seconds_to_time(Seconds) -> Time</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Seconds = int() < 86400</CODE></STRONG><BR>
<STRONG><CODE>Time = time()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This function computes the time from the given number of
seconds. <CODE>Seconds</CODE> must be less than the number of
seconds per day (86400).
</DIV>
<P><A NAME="time_difference/2"><STRONG><CODE>time_difference(T1, T2) -> {Days, Time}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This function returns the difference between two <CODE>{Date,
Time}</CODE> tuples. <CODE>T2</CODE> should refer to an epoch later
than <CODE>T1</CODE>.
<P>
<TABLE CELLPADDING=4>
<TR>
<TD VALIGN=TOP><IMG ALT="Warning!" SRC="warning.gif"></TD>
<TD>
<P>This function is obsolete. Use the conversion functions for
gregorian days and seconds instead. </TD>
</TR>
</TABLE>
</DIV>
<P><A NAME="time_to_seconds/1"><STRONG><CODE>time_to_seconds(Time) -> Seconds</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Time = time()</CODE></STRONG><BR>
<STRONG><CODE>Seconds = int()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This function computes the number of seconds since midnight
up to the specified time.
</DIV>
<P><A NAME="universal_time/0"><STRONG><CODE>universal_time() -> {Date, Time}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Date = date()</CODE></STRONG><BR>
<STRONG><CODE>Time = time()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This function returns the Universal Coordinated Time (UTC)
reported by the underlying operating system. Local time is
returned if universal time is not available.
</DIV>
<P><A NAME="universal_time_to_local_time/2"><STRONG><CODE>universal_time_to_local_time({Date1, Time1}) ->
{Date2, Time2}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Date1 = Date2 = date()</CODE></STRONG><BR>
<STRONG><CODE>Time1 = Time2 = time()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This function converts from Universal Coordinated Time (UTC)
to local time. <CODE>Date1</CODE> must refer to a date after Jan 1,
1970.
</DIV>
<P><A NAME="valid_date/1"><STRONG><CODE>valid_date(Date) -> bool()</CODE></STRONG></A><BR>
<A NAME="valid_date/3"><STRONG><CODE>valid_date(Year, Month, Day) -> bool()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Date = date()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This function checks if a date is a valid.
</DIV>
<H3>Leap Years</H3>
<DIV CLASS=REFBODY>
<P>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:
<P>
<UL>
<LI>
Y is divisible by 4, but not by 100; or<BR>
</LI>
<LI>
Y is divisible by 400.<BR>
</LI>
</UL>
<P>Accordingly, 1996 is a leap year, 1900 is not, but 2000 is.
</DIV>
<H3>Date and Time Source</H3>
<DIV CLASS=REFBODY>
<P>Local time is obtained from the Erlang BIF <CODE>localtime/0</CODE>.
Universal time is computed from the BIF <CODE>universaltime/0</CODE>.
<P>The following facts apply:
<P>
<UL>
<LI>
there are 86400 seconds in a day
</LI>
<LI>
there are 365 days in an ordinary year
</LI>
<LI>
there are 366 days in a leap year
</LI>
<LI>
there are 1461 days in a 4 year period
</LI>
<LI>
there are 36524 days in a 100 year period
</LI>
<LI>
there are 146097 days in a 400 year period
</LI>
<LI>
there are 719528 days between Jan 1, 0 and Jan 1, 1970.
</LI>
</UL>
</DIV>
<H3>AUTHORS</H3>
<DIV CLASS=REFBODY>
Peter Hgfeldt - support@erlang.ericsson.se<BR>
</DIV>
<CENTER>
<HR>
<SMALL>stdlib 1.14.2<BR>
Copyright © 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>
|