diff options
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | include/mailutils/datetime.h | 23 | ||||
-rw-r--r-- | libmailutils/Makefile.am | 3 | ||||
-rw-r--r-- | libmailutils/base/Makefile.am | 2 | ||||
-rw-r--r-- | libmailutils/base/date.c | 1163 | ||||
-rw-r--r-- | libmailutils/datetime/Makefile.am | 32 | ||||
-rw-r--r-- | libmailutils/datetime/dow.c | 29 | ||||
-rw-r--r-- | libmailutils/datetime/doy.c | 53 | ||||
-rw-r--r-- | libmailutils/datetime/jd.c | 32 | ||||
-rw-r--r-- | libmailutils/datetime/scantime.c | 660 | ||||
-rw-r--r-- | libmailutils/datetime/streamftime.c | 411 | ||||
-rw-r--r-- | libmailutils/datetime/strftime.c (renamed from libmailutils/base/strftime.c) | 0 | ||||
-rw-r--r-- | libmailutils/datetime/tab.c | 45 | ||||
-rw-r--r-- | libmailutils/datetime/unixtime.c | 38 | ||||
-rw-r--r-- | libmailutils/datetime/utcoff.c | 32 | ||||
-rw-r--r-- | libmailutils/datetime/yd.c | 29 | ||||
-rw-r--r-- | libmailutils/tests/scantime.at | 58 | ||||
-rw-r--r-- | libmailutils/tests/scantime.c | 2 |
18 files changed, 1416 insertions, 1197 deletions
diff --git a/configure.ac b/configure.ac index 62b4409d1..dfacf09fe 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -1470,6 +1470,7 @@ AC_CONFIG_FILES([ | |||
1470 | libmailutils/sockaddr/Makefile | 1470 | libmailutils/sockaddr/Makefile |
1471 | libmailutils/cidr/Makefile | 1471 | libmailutils/cidr/Makefile |
1472 | libmailutils/cfg/Makefile | 1472 | libmailutils/cfg/Makefile |
1473 | libmailutils/datetime/Makefile | ||
1473 | libmailutils/diag/Makefile | 1474 | libmailutils/diag/Makefile |
1474 | libmailutils/filter/Makefile | 1475 | libmailutils/filter/Makefile |
1475 | libmailutils/imapio/Makefile | 1476 | libmailutils/imapio/Makefile |
diff --git a/include/mailutils/datetime.h b/include/mailutils/datetime.h index 0ad84b595..de00618a0 100644 --- a/include/mailutils/datetime.h +++ b/include/mailutils/datetime.h | |||
@@ -24,6 +24,29 @@ | |||
24 | /* ----------------------- */ | 24 | /* ----------------------- */ |
25 | /* Date & time functions */ | 25 | /* Date & time functions */ |
26 | /* ----------------------- */ | 26 | /* ----------------------- */ |
27 | |||
28 | /* Argument ranges: | ||
29 | |||
30 | year != 0, AD if > 0, BC if < 0 | ||
31 | 1 <= month <= 12 | ||
32 | 1 <= day <= maxday(month) | ||
33 | */ | ||
34 | /* Compute Julian Day for the given date */ | ||
35 | int mu_datetime_julianday (int year, int month, int day); | ||
36 | /* Compute day of week (Sunday - 0) */ | ||
37 | int mu_datetime_dayofweek (int year, int month, int day); | ||
38 | /* Compute ordinal date (1-based) */ | ||
39 | int mu_datetime_dayofyear (int year, int month, int day); | ||
40 | /* Return number of days in the year */ | ||
41 | int mu_datetime_year_days (int year); | ||
42 | |||
43 | /* Day of week and month names in C locale */ | ||
44 | extern const char *_mu_datetime_short_month[]; | ||
45 | extern const char *_mu_datetime_full_month[]; | ||
46 | extern const char *_mu_datetime_short_wday[]; | ||
47 | extern const char *_mu_datetime_full_wday[]; | ||
48 | |||
49 | |||
27 | struct mu_timezone | 50 | struct mu_timezone |
28 | { | 51 | { |
29 | int utc_offset; /* Seconds east of UTC. */ | 52 | int utc_offset; /* Seconds east of UTC. */ |
diff --git a/libmailutils/Makefile.am b/libmailutils/Makefile.am index b32138250..c01b32176 100644 --- a/libmailutils/Makefile.am +++ b/libmailutils/Makefile.am | |||
@@ -19,7 +19,7 @@ | |||
19 | SUBDIRS = \ | 19 | SUBDIRS = \ |
20 | auth base address list sockaddr cidr cfg diag\ | 20 | auth base address list sockaddr cidr cfg diag\ |
21 | filter mailbox mailer mime server string stream stdstream\ | 21 | filter mailbox mailer mime server string stream stdstream\ |
22 | property url imapio . tests | 22 | property url imapio datetime . tests |
23 | 23 | ||
24 | lib_LTLIBRARIES = libmailutils.la | 24 | lib_LTLIBRARIES = libmailutils.la |
25 | 25 | ||
@@ -33,6 +33,7 @@ libmailutils_la_LIBADD = \ | |||
33 | sockaddr/libsockaddr.la\ | 33 | sockaddr/libsockaddr.la\ |
34 | cidr/libcidr.la\ | 34 | cidr/libcidr.la\ |
35 | cfg/libcfg.la\ | 35 | cfg/libcfg.la\ |
36 | datetime/libdatetime.la\ | ||
36 | diag/libdiag.la\ | 37 | diag/libdiag.la\ |
37 | filter/libfilter.la\ | 38 | filter/libfilter.la\ |
38 | imapio/libimapio.la\ | 39 | imapio/libimapio.la\ |
diff --git a/libmailutils/base/Makefile.am b/libmailutils/base/Makefile.am index a2e5ac5b6..4b9a3759d 100644 --- a/libmailutils/base/Makefile.am +++ b/libmailutils/base/Makefile.am | |||
@@ -26,7 +26,6 @@ libbase_la_SOURCES = \ | |||
26 | assoc.c\ | 26 | assoc.c\ |
27 | filesafety.c\ | 27 | filesafety.c\ |
28 | daemon.c\ | 28 | daemon.c\ |
29 | date.c\ | ||
30 | fdwait.c\ | 29 | fdwait.c\ |
31 | fgetpwent.c\ | 30 | fgetpwent.c\ |
32 | filename.c\ | 31 | filename.c\ |
@@ -61,7 +60,6 @@ libbase_la_SOURCES = \ | |||
61 | sha1.c\ | 60 | sha1.c\ |
62 | secret.c\ | 61 | secret.c\ |
63 | spawnvp.c\ | 62 | spawnvp.c\ |
64 | strftime.c\ | ||
65 | symlink.c\ | 63 | symlink.c\ |
66 | tempfile.c\ | 64 | tempfile.c\ |
67 | ticket.c\ | 65 | ticket.c\ |
diff --git a/libmailutils/base/date.c b/libmailutils/base/date.c deleted file mode 100644 index b3182538d..000000000 --- a/libmailutils/base/date.c +++ /dev/null | |||
@@ -1,1163 +0,0 @@ | |||
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001, 2002, 2007, 2009, 2010, 2011 Free | ||
3 | Software Foundation, Inc. | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 3 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General | ||
16 | Public License along with this library. If not, see | ||
17 | <http://www.gnu.org/licenses/>. */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
22 | #include <stdio.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <string.h> | ||
25 | #include <mailutils/diag.h> | ||
26 | #include <mailutils/datetime.h> | ||
27 | #include <mailutils/util.h> | ||
28 | #include <mailutils/stream.h> | ||
29 | #include <mailutils/errno.h> | ||
30 | #include <mailutils/cstr.h> | ||
31 | #include <mailutils/cctype.h> | ||
32 | |||
33 | #define SECS_PER_DAY 86400 | ||
34 | #define ADJUSTMENT -719162L | ||
35 | |||
36 | /* Julian day is the number of days since Jan 1, 4713 BC (ouch!). | ||
37 | Eg. Jan 1, 1900 is: */ | ||
38 | #define JULIAN_1900 1721425L | ||
39 | |||
40 | /* Computes the number of days elapsed since January, 1 1900 to the | ||
41 | January, 1 of the given year */ | ||
42 | static unsigned | ||
43 | jan1st (int year) | ||
44 | { | ||
45 | year--; /* Do not consider the current year */ | ||
46 | return year * 365L | ||
47 | + year/4L /* Years divisible by 4 are leap years */ | ||
48 | + year/400L /* Years divisible by 400 are always leap years */ | ||
49 | - year/100L; /* Years divisible by 100 but not 400 aren't */ | ||
50 | } | ||
51 | |||
52 | static int month_start[]= | ||
53 | { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; | ||
54 | /* Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec | ||
55 | 31 28 31 30 31 30 31 31 30 31 30 31 | ||
56 | */ | ||
57 | |||
58 | #define leap_year(y) ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0)) | ||
59 | |||
60 | static int | ||
61 | dayofyear (int year, int month, int day) | ||
62 | { | ||
63 | int leap, month_days; | ||
64 | |||
65 | if (year < 0 || month < 0 || month > 11) | ||
66 | return -1; | ||
67 | |||
68 | leap = leap_year (year); | ||
69 | |||
70 | month_days = month_start[month + 1] - month_start[month] | ||
71 | + ((month == 2) ? leap : 0); | ||
72 | |||
73 | if (day < 0 || day > month_days) | ||
74 | return -1; /* Illegal Date */ | ||
75 | |||
76 | if (month <= 2) | ||
77 | leap = 0; | ||
78 | |||
79 | return month_start[month] + day + leap; | ||
80 | } | ||
81 | |||
82 | /* Returns number of days in a given year */ | ||
83 | static int | ||
84 | year_days (int year) | ||
85 | { | ||
86 | return dayofyear (year, 11, 31); | ||
87 | } | ||
88 | |||
89 | static int | ||
90 | julianday (unsigned *pd, int year, int month, int day) | ||
91 | { | ||
92 | int total = dayofyear (year, month, day); | ||
93 | if (total == -1) | ||
94 | return -1; | ||
95 | *pd = JULIAN_1900 + total + jan1st (year); | ||
96 | return 0; | ||
97 | } | ||
98 | |||
99 | static int | ||
100 | dayofweek (int year, int month, int day) | ||
101 | { | ||
102 | unsigned jd; | ||
103 | |||
104 | if (julianday (&jd, year, month, day)) | ||
105 | return -1; | ||
106 | |||
107 | /* January 1, 1900 was Monday, hence +1 */ | ||
108 | return (jd + 1) % 7; | ||
109 | } | ||
110 | |||
111 | #define ISO_8601_START_WDAY 1 /* Monday */ | ||
112 | #define ISO_8601_MAX_WDAY 4 /* Thursday */ | ||
113 | #define MAXDAYS 366 /* Max. number of days in a year */ | ||
114 | #define ISO_8601_OFF ((MAXDAYS / 7 + 2) * 7) | ||
11 |