big dialogs: set_curosr2 -> set_dlg_cursor.
[elinks.git] / src / protocol / README.timegm
blob9b53169c4dc13c6e5a7008ca46a4b1c14cc4f9d9
1 This file contains description of our my_timegm() function in date.c. It was
2 posted as a mail to links-list by Stephane Chazelas, and I thought it may be
3 interesting for someone, so I decided to include it in the ELinks distribution.
8 Un explanation for it as one (me to start with) may wonder why
9 this works.
11 We first change of calendar. To make things easy, let's say
12 that 0/0/0 0:0:0 in our new calendar is the Marsh 1st 1968, so
13 just after a february 29th as 1968 was a leap year.
15 if y/m/d h:min:s is time in our calendar
16 and
17    Y/M/D h:min:s in the new calendar
19 M = m - 1 - 2 (+ 12 if m < 3)
20 Y = y - 68 (-1 if m < 3)
21 D = d - 1
23 at Y/0/0 0:0:0, there has been Y / 4 leap years in the past, so
24 (int) 365 * Y + Y / 4 days have past.
26 at Y/M/0 0:0:0, lets find how many days have past since Y/0/0:
28                    |Mar                                        Feb
29                   M| 0   1   2   3   4   5   6   7   8   9  10  11
30 -------------------+-----------------------------------------------
31  days in that month|31  30  31  30  31  31  30  31  30  31  31  28 or 29
32 -------------------+-----------------------------------------------
33   x = days at Y/M/0| 0  31  61  92 122 153 184 214 245 275 306 337
34 -------------------+-----------------------------------------------
35 first approximation|
36          y = 30 * M| 0  30  60  90 120 150 180 210 240 270 300 330
37 -------------------+-----------------------------------------------
38               x - y| 0   1   1   2   2   3   4   4   5   5   6   7
39 -------------------+-----------------------------------------------
40 (M + 4) * 3 / 5 - 2| 0   1   1   2   2   3   4   4   5   5   6   7
41 -------------------+-----------------------------------------------
43 x - y = (M + 4) * 3 / 5 - 2
45 x = 30 * M + (M + 4) * 3 / 5 - 2
47 x = (153 * M + 2) / 5
49 So at Y/M/D 0:0:0,
51 Y * 1461 / 4 + (153 * M + 2) / 5 + D days have past since
52 the 1st of March of 1968
54 1st of March of 1968 was 671 days before 1970 Jan 1st (year 0
55 for unix time())
58 t = s + 60 * (min + 60 * (h + 24 * (Y * 1461 / 4 + (153 * M + 2) / 5 + D - 671)))
59 t = s + 60 * (min + 60 * (h + 24 * (Y * 1461 / 4 + (153 * M + 2) / 5 + d - 672)))
61 This shouldn't work past 2100/02/28 23:59:59 as 2100 is not a leap year.
64 Stéphane