Use locale to guess the switch date.
Localize formatting of date of easter. Suggested by: ache
This commit is contained in:
parent
cdd3ffeafb
commit
d44de6c864
@ -22,7 +22,7 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $Id: ncal.1,v 1.1.1.1 1997/12/15 20:35:22 helbig Exp $
|
||||
.\" $Id: ncal.1,v 1.2 1997/12/19 21:41:21 helbig Exp $
|
||||
.\"
|
||||
.Dd December 16, 1997
|
||||
.Dt CAL 1
|
||||
@ -57,8 +57,6 @@ The options are as follows:
|
||||
Display Julian Calendar, if combined with the
|
||||
.Fl e
|
||||
option, display date of easter according to the Julian Calendar.
|
||||
If not specified, the Julian Calendar is assumed till October 4, 1582
|
||||
and the Gregorian Calendar thereafter.
|
||||
.It Fl e
|
||||
Display date of easter (for western churches).
|
||||
.It Fl j
|
||||
@ -70,17 +68,17 @@ Orthodox Churches).
|
||||
Print the country codes and switching days from Julian to Gregorian
|
||||
Calendar as they are assumed by
|
||||
.Nm ncal .
|
||||
The country code as determined from the local environment is marked
|
||||
with an asterisk.
|
||||
.It Fl s Ar country-code
|
||||
Assume the switch from Julian to Gregorian Calendar at the date
|
||||
associated with the
|
||||
.Ar country-code .
|
||||
If not specified,
|
||||
.Nm ncal
|
||||
assumes October 4, 1582 (on this day the Catholic Church switched to Gregorian
|
||||
Calendar) and
|
||||
.Nm cal
|
||||
thinks with Great Britain and her colonies that
|
||||
September 2, 1752 was the date to switch to Gregorian Calendar.
|
||||
tries to guess the switch date from the local environment or
|
||||
falls back to September 2, 1752. This was when Great
|
||||
Britain and her colonies switched to the Gregorian Calendar.
|
||||
.It Fl w
|
||||
Print the number of the week below each week column.
|
||||
.It Fl y
|
||||
@ -114,3 +112,6 @@ command appeared in
|
||||
This
|
||||
manual page and the command was written by
|
||||
.An Wolfgang Helbig Aq helbig@FreeBSD.ORG .
|
||||
.Sh BUGS
|
||||
The assignment of Julian - Gregorian switching dates to
|
||||
country codes is historically naive for many countries.
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: ncal.c,v 1.1.1.1 1997/12/15 20:35:22 helbig Exp $
|
||||
* $Id: ncal.c,v 1.2 1997/12/31 15:55:08 helbig Exp $
|
||||
*/
|
||||
#include <calendar.h>
|
||||
#include <err.h>
|
||||
@ -61,36 +61,46 @@ static struct djswitch {
|
||||
char *cc; /* Country code according to ISO 3166 */
|
||||
char *nm; /* Name of country */
|
||||
date dt; /* Last day of Julian calendar */
|
||||
char *efmt; /* strftime format for printing date of easter */
|
||||
} switches[] = {
|
||||
{"AL", "Albania", {1912, 11, 30}},
|
||||
{"BG", "Bulgaria", {1916, 3, 18}},
|
||||
{"CA", "Canada", {1752, 9, 2}},
|
||||
{"CH", "Switzerland", {1655, 2, 28}},
|
||||
{"CN", "China", {1911, 12, 18}},
|
||||
{"CZ", "Czech Republic",{1584, 1, 6}},
|
||||
{"DE", "Germany", {1700, 2, 18}},
|
||||
{"DK", "Denmark", {1700, 2, 18}},
|
||||
{"ES", "Spain", {1582, 10, 4}},
|
||||
{"FR", "France", {1582, 12, 9}},
|
||||
{"GB", "United Kingdom",{1752, 9, 2}},
|
||||
{"GR", "Greece", {1924, 3, 9}},
|
||||
{"HU", "Hungary", {1587, 10, 21}},
|
||||
{"IS", "Iceland", {1700, 11, 16}},
|
||||
{"IT", "Italy", {1582, 10, 4}},
|
||||
{"JP", "Japan", {1918, 12, 18}},
|
||||
{"LV", "Latvia", {1918, 2, 1}},
|
||||
{"LI", "Lithuania", {1918, 2, 1}},
|
||||
{"NL", "Netherlands", {1701, 4, 30}},
|
||||
{"NO", "Norway", {1700, 2, 18}},
|
||||
{"PT", "Portugal", {1582, 10, 4}},
|
||||
{"RO", "Romania", {1920, 3, 4}},
|
||||
{"RU", "Russia", {1920, 3, 4}},
|
||||
{"SW", "Sweden", {1753, 2, 17}},
|
||||
{"TR", "Turkey", {1926, 12, 18}},
|
||||
{"US", "United States", {1752, 9, 2}},
|
||||
{"YU", "Yugoslavia", {1919, 3, 4}},
|
||||
{"AL", "Albania", {1912, 11, 30}, "%e %B %Y"},
|
||||
{"AT", "Austria", {1582, 10, 4}, "%e. %B %Y"},
|
||||
{"AU", "Australia", {1752, 9, 2}, "%B %e, %Y"},
|
||||
{"BG", "Bulgaria", {1916, 3, 18}, "%e %B %Y"},
|
||||
{"CA", "Canada", {1752, 9, 2}, "%B %e, %Y"},
|
||||
{"CH", "Switzerland", {1655, 2, 28}, "%e. %B %Y"},
|
||||
{"CN", "China", {1911, 12, 18}, "%e %B %Y"},
|
||||
{"CZ", "Czech Republic",{1584, 1, 6}, "%e %B %Y"},
|
||||
{"DE", "Germany", {1700, 2, 18}, "%e. %B %Y"},
|
||||
{"DK", "Denmark", {1700, 2, 18}, "%e. %B %Y"},
|
||||
{"ES", "Spain", {1582, 10, 4}, "%e de %B de %Y"},
|
||||
{"FR", "France", {1582, 12, 9}, "%e. %B %Y"},
|
||||
{"GB", "United Kingdom",{1752, 9, 2}, "%e %B %Y"},
|
||||
{"GR", "Greece", {1924, 3, 9}, "%e %B %Y"},
|
||||
{"HU", "Hungary", {1587, 10, 21}, "%e %B %Y"},
|
||||
{"IS", "Iceland", {1700, 11, 16}, "%e %B %Y"},
|
||||
{"IT", "Italy", {1582, 10, 4}, "%e %B %Y"},
|
||||
{"JP", "Japan", {1918, 12, 18}, "%Y\x94N %B%e"},
|
||||
{"LV", "Latvia", {1918, 2, 1}, "%e %B %Y"},
|
||||
{"LI", "Lithuania", {1918, 2, 1}, "%e %B %Y"},
|
||||
{"NL", "Netherlands", {1701, 4, 30}, "%e %B %Y"},
|
||||
{"NO", "Norway", {1700, 2, 18}, "%e %B %Y"},
|
||||
{"PL", "Poland", {1582, 10, 4}, "%e %B %Y"},
|
||||
{"PT", "Portugal", {1582, 10, 4}, "%e %B %Y"},
|
||||
{"RO", "Romania", {1920, 3, 4}, "%e %B %Y"},
|
||||
{"RU", "Russia", {1920, 3, 4}, "%e %B %Y"},
|
||||
{"SI", "Slovenia", {1919, 3, 4}, "%e %B %Y"},
|
||||
{"SU", "USSR", {1920, 3, 4}, "%e %B %Y"},
|
||||
{"SW", "Sweden", {1753, 2, 17}, "%e %B %Y"},
|
||||
{"TR", "Turkey", {1926, 12, 18}, "%e %B %Y"},
|
||||
{"US", "United States", {1752, 9, 2}, "%B %e, %Y"},
|
||||
{"YU", "Yugoslavia", {1919, 3, 4}, "%e %B %Y"}
|
||||
};
|
||||
|
||||
struct djswitch *dftswitch =
|
||||
switches + sizeof(switches) / sizeof(struct djswitch) - 2;
|
||||
/* default switch (should be "US") */
|
||||
|
||||
/* Table used to print day of month and week numbers */
|
||||
char daystr[] = " 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"
|
||||
@ -139,6 +149,7 @@ char jdaystr[] = " 1 2 3 4 5 6 7 8 9"
|
||||
int flag_weeks; /* user wants number of week */
|
||||
int nswitch; /* user defined switch date */
|
||||
int nswitchb; /* switch date for backward compatibility */
|
||||
char *efmt; /* strftime format string for printeaster() */
|
||||
|
||||
char *center(char *s, char *t, int w);
|
||||
void mkmonth(int year, int month, int jd_flag, struct monthlines * monthl);
|
||||
@ -174,8 +185,30 @@ main(int argc, char *argv[])
|
||||
int flag_orthodox = 0; /* use wants Orthodox easter */
|
||||
int flag_easter = 0; /* use wants easter date */
|
||||
char *cp; /* character pointer */
|
||||
char *locale; /* locale to get country code */
|
||||
|
||||
/*
|
||||
* Use locale to determine the country code,
|
||||
* and use the country code to determine the default
|
||||
* switchdate and date format from the switches table.
|
||||
*/
|
||||
if ((locale = setlocale(LC_TIME, "")) == NULL)
|
||||
warn("setlocale");
|
||||
if (locale == NULL || locale == "C")
|
||||
locale = "_US";
|
||||
q = switches + sizeof(switches) / sizeof(struct djswitch);
|
||||
for (p = switches; p != q; p++)
|
||||
if ((cp = strstr(locale, p->cc)) != NULL && *(cp - 1) == '_')
|
||||
break;
|
||||
if (p == q) {
|
||||
nswitch = ndaysj(&dftswitch->dt);
|
||||
efmt = dftswitch->efmt;
|
||||
} else {
|
||||
nswitch = ndaysj(&p->dt);
|
||||
efmt = p->efmt;
|
||||
dftswitch = p;
|
||||
}
|
||||
|
||||
setlocale(LC_TIME, "");
|
||||
|
||||
/*
|
||||
* Get the filename portion of argv[0] and set flag_backward if
|
||||
@ -312,20 +345,17 @@ printcc(void)
|
||||
int n; /* number of lines to print */
|
||||
int m; /* offset from left to right table entry on the same line */
|
||||
|
||||
#define FSTR "%s %-15s %4d-%02d-%02d"
|
||||
#define FSTR "%c%s %-15s%4d-%02d-%02d"
|
||||
#define DFLT(p) ((p) == dftswitch ? '*' : ' ')
|
||||
#define FSTRARG(p) DFLT(p), (p)->cc, (p)->nm, (p)->dt.y, (p)->dt.m, (p)->dt.d
|
||||
|
||||
n = sizeof(switches) / sizeof(struct djswitch);
|
||||
m = (n + 1) / 2;
|
||||
n /= 2;
|
||||
for (p = switches; p != switches + n; p++) {
|
||||
printf(FSTR" "FSTR"\n" ,
|
||||
p->cc, p->nm, p->dt.y, p->dt.m, p->dt.d,
|
||||
(p+m)->cc, (p+m)->nm, (p+m)->dt.y,
|
||||
(p+m)->dt.m, (p+m)->dt.d);
|
||||
}
|
||||
for (p = switches; p != switches + n; p++)
|
||||
printf(FSTR" "FSTR"\n", FSTRARG(p), FSTRARG(p+m));
|
||||
if (m != n)
|
||||
printf(FSTR"\n",
|
||||
p->cc, p->nm, p->dt.y, p->dt.m, p->dt.d);
|
||||
printf(FSTR"\n", FSTRARG(p));
|
||||
}
|
||||
|
||||
/* print the date of easter sunday */
|
||||
@ -333,6 +363,8 @@ void
|
||||
printeaster(int y, int julian, int orthodox)
|
||||
{
|
||||
date dt;
|
||||
struct tm tm;
|
||||
char buf[80];
|
||||
|
||||
/* force orthodox easter for years before 1583 */
|
||||
if (y < 1583)
|
||||
@ -345,7 +377,13 @@ printeaster(int y, int julian, int orthodox)
|
||||
easterog(y, &dt);
|
||||
else
|
||||
easterg(y, &dt);
|
||||
printf("%04d-%02d-%02d\n", dt.y, dt.m, dt.d);
|
||||
|
||||
memset(&tm, 0, sizeof(tm));
|
||||
tm.tm_year = dt.y - 1900;
|
||||
tm.tm_mon = dt.m - 1;
|
||||
tm.tm_mday = dt.d;
|
||||
strftime(buf, sizeof(buf), efmt, &tm);
|
||||
printf("%s\n", buf);
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user