1
0
Fork 0
elinks/src/protocol
Witold Filipczyk 5ca979844b [Makefiles] Added --with-libcurl configure option 2023-07-02 14:49:51 +02:00
..
auth [auth] const in add_auth_entry 2022-02-17 20:33:16 +01:00
bittorrent [lists] LIST_HEAD -> LIST_HEAD_EL to not clash with libevent's LIST_HEAD. Also added curl implementation of ftpes and sftp 2023-06-19 18:43:53 +02:00
curl [Makefiles] Added --with-libcurl configure option 2023-07-02 14:49:51 +02:00
file [dgi] Unification. 2022-07-14 22:29:24 +02:00
finger [c] More fixes related to redefined PF_INET 2021-12-22 16:27:29 +01:00
fsp [network] enum connection_basic_state -> connection_basic_state_T 2022-01-28 16:25:40 +01:00
ftp [ftp] Added bool option "protocol.ftp.use_curl" 2023-06-22 19:39:13 +02:00
gemini [long] long -> intptr_t . Refs #8304 2022-08-17 20:48:58 +02:00
gopher [gopher] const format 2022-02-21 17:15:48 +01:00
http [curl] Added bool option "protocol.http.use_curl" 2023-06-29 16:39:17 +02:00
nntp [options] No need for C_ macro in INIT_OPT_* 2022-03-02 19:02:47 +01:00
rewrite [options] No need for C_ macro in INIT_OPT_* 2022-03-02 19:02:47 +01:00
smb [auth] cast 2022-01-26 17:21:42 +01:00
test [test] Compilation fix 2023-06-28 12:33:25 +02:00
Makefile [Makefiles] Added --with-libcurl configure option 2023-07-02 14:49:51 +02:00
README.timegm Move README.timegm to the same directory as date.c. 2007-01-13 10:01:51 +02:00
about.c [about] const 2022-02-02 18:53:51 +01:00
about.h [mozjs24] Allow build elinks with g++ 2020-10-05 20:14:55 +02:00
common.c [document] Try to set system charset. 2022-11-10 13:25:37 +01:00
common.h [mozjs24] Allow build elinks with g++ 2020-10-05 20:14:55 +02:00
data.c [data] const type 2022-02-21 17:52:17 +01:00
data.h [mozjs24] Allow build elinks with g++ 2020-10-05 20:14:55 +02:00
date.c [time.h] time.h can be included unconditionally 2021-03-19 14:22:04 +01:00
date.h [cflags] Removed -Wno-pointer-sign 2021-01-02 16:20:27 +01:00
header.c [http] const in get_header_param 2022-02-17 20:39:07 +01:00
header.h [http] const in get_header_param 2022-02-17 20:39:07 +01:00
meson.build [config] curl's ftp related code requires libevent. Refs #240 2023-06-22 20:07:08 +02:00
protocol.cpp [curl] Begining of curl's http 2023-06-25 18:21:35 +02:00
protocol.h [sftp] Copy-paste (fork and curl) 2023-06-17 19:06:43 +02:00
proxy.c [protocol] more const in get_protocol_proxy 2022-02-17 20:22:29 +01:00
proxy.h [mozjs24] Allow build elinks with g++ 2020-10-05 20:14:55 +02:00
uri.c [uri] Encode only bytes with highest bit set. Refs #226 2023-04-27 14:28:19 +02:00
uri.h [uri] Introduced function encode_uri_string_percent. Refs #221 2023-04-23 15:05:58 +02:00
user.c [options] No need for C_ macro in INIT_OPT_* 2022-03-02 19:02:47 +01:00
user.h [cache] const in redirect_cache 2022-02-21 17:13:14 +01:00

README.timegm

This file contains description of our my_timegm() function in date.c. It was
posted as a mail to links-list by Stephane Chazelas, and I thought it may be
interesting for someone, so I decided to include it in the ELinks distribution.




Un explanation for it as one (me to start with) may wonder why
this works.

We first change of calendar. To make things easy, let's say
that 0/0/0 0:0:0 in our new calendar is the Marsh 1st 1968, so
just after a february 29th as 1968 was a leap year.

if y/m/d h:min:s is time in our calendar
and
   Y/M/D h:min:s in the new calendar

M = m - 1 - 2 (+ 12 if m < 3)
Y = y - 68 (-1 if m < 3)
D = d - 1

at Y/0/0 0:0:0, there has been Y / 4 leap years in the past, so
(int) 365 * Y + Y / 4 days have past.

at Y/M/0 0:0:0, lets find how many days have past since Y/0/0:

                   |Mar                                        Feb
                  M| 0   1   2   3   4   5   6   7   8   9  10  11
-------------------+-----------------------------------------------
 days in that month|31  30  31  30  31  31  30  31  30  31  31  28 or 29
-------------------+-----------------------------------------------
  x = days at Y/M/0| 0  31  61  92 122 153 184 214 245 275 306 337
-------------------+-----------------------------------------------
first approximation|
         y = 30 * M| 0  30  60  90 120 150 180 210 240 270 300 330
-------------------+-----------------------------------------------
              x - y| 0   1   1   2   2   3   4   4   5   5   6   7
-------------------+-----------------------------------------------
(M + 4) * 3 / 5 - 2| 0   1   1   2   2   3   4   4   5   5   6   7
-------------------+-----------------------------------------------

x - y = (M + 4) * 3 / 5 - 2

x = 30 * M + (M + 4) * 3 / 5 - 2

x = (153 * M + 2) / 5

So at Y/M/D 0:0:0,

Y * 1461 / 4 + (153 * M + 2) / 5 + D days have past since
the 1st of March of 1968

1st of March of 1968 was 671 days before 1970 Jan 1st (year 0
for unix time())

So
t = s + 60 * (min + 60 * (h + 24 * (Y * 1461 / 4 + (153 * M + 2) / 5 + D - 671)))
t = s + 60 * (min + 60 * (h + 24 * (Y * 1461 / 4 + (153 * M + 2) / 5 + d - 672)))

This shouldn't work past 2100/02/28 23:59:59 as 2100 is not a leap year.

--
St<E9>phane