From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONTRIB/SNIP/calsupp.c | 65 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 reference/C/CONTRIB/SNIP/calsupp.c (limited to 'reference/C/CONTRIB/SNIP/calsupp.c') diff --git a/reference/C/CONTRIB/SNIP/calsupp.c b/reference/C/CONTRIB/SNIP/calsupp.c new file mode 100755 index 0000000..113f08a --- /dev/null +++ b/reference/C/CONTRIB/SNIP/calsupp.c @@ -0,0 +1,65 @@ +/* calsupp.c -- public domain by Ray McVay */ + +/* This module provides three handy date related functions: +** dow() - Returns the day of the week for a given date +** IsLeap() - Returns 1 if a year is a leap year +** GetToday() - Returns today's date from the operating system +*/ + +#include + +/* +** Returns an integer that represents the day of the week for +** the date passed as parameters. +** +** day: day of month +** mon: month (1-12) +** yr: year +** +** returns 0-6 where 0 == sunday +*/ + +int dow(int day, int mon, int yr) +{ + int dow; + + if (mon <= 2) + { + mon += 12; + yr -= 1; + } + dow = (day + mon * 2 + ((mon + 1) * 6) / 10 + + yr + yr / 4 - yr / 100 + yr / 400 + 2); + dow = dow % 7; + return ((dow ? dow : 7) - 1); +} + + +/* +** Returns 1 if yr is a leap year, 0 if it is not +*/ + +int IsLeap(int yr) +{ + if (yr % 400 == 0) return 1; + if (yr % 100 == 0) return 0; + if (yr % 4 == 0) return 1; + else return 0; +} + + +/* +** Returns the current day, month and year in the referenced variables +*/ + +void GetToday(int *day, int *mon, int *yr) +{ + struct tm today; + time_t ctime; + + time(&ctime); + today = *localtime(&ctime); + *day = today.tm_mday; + *mon = today.tm_mon + 1; + *yr = today.tm_year + 1900; +} -- cgit v1.2.3-54-g00ecf