unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
blob 6d761645693d11934b265ed8ec027549d4e15c10 960 bytes (raw)
name: compat/timegm.c 	 # note: path name is non-authoritative(*)

 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
 
#include <time.h>
#include "compat.h"

static int
leapyear (int year)
{
    return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));
}

/*
 * This is a simple implementation of timegm() which does what is needed
 * by create_output() -- just turns the "struct tm" into a GMT time_t.
 * It does not normalize any of the fields of the "struct tm", nor does
 * it set tm_wday or tm_yday.
 */
time_t
timegm (struct tm *tm)
{
    int	monthlen[2][12] = {
	{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
	{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
    };
    int	year, month, days;

    days = 365 * (tm->tm_year - 70);
    for (year = 70; year < tm->tm_year; year++) {
	if (leapyear(1900 + year)) {
	    days++;
	}
    }
    for (month = 0; month < tm->tm_mon; month++) {
	days += monthlen[leapyear(1900 + year)][month];
    }
    days += tm->tm_mday - 1;

    return ((((days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec);
}

debug log:

solving 6d76164 ...
found 6d76164 in https://yhetil.org/notmuch/1376663897-24385-5-git-send-email-Vladimir.Marek@oracle.com/ ||
	https://yhetil.org/notmuch/1367853362-11846-5-git-send-email-Vladimir.Marek@oracle.com/ ||
	https://yhetil.org/notmuch/1352859005-18631-11-git-send-email-blakej@foo.net/ ||
	https://yhetil.org/notmuch/1352142123-18286-11-git-send-email-blakej@foo.net/

applying [1/1] https://yhetil.org/notmuch/1376663897-24385-5-git-send-email-Vladimir.Marek@oracle.com/
diff --git a/compat/timegm.c b/compat/timegm.c
new file mode 100644
index 0000000..6d76164

Checking patch compat/timegm.c...
Applied patch compat/timegm.c cleanly.

skipping https://yhetil.org/notmuch/1367853362-11846-5-git-send-email-Vladimir.Marek@oracle.com/ for 6d76164
skipping https://yhetil.org/notmuch/1352859005-18631-11-git-send-email-blakej@foo.net/ for 6d76164
skipping https://yhetil.org/notmuch/1352142123-18286-11-git-send-email-blakej@foo.net/ for 6d76164
index at:
100644 6d761645693d11934b265ed8ec027549d4e15c10	compat/timegm.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).