this repo has no description
at main 117 lines 4.1 kB view raw
1/* 2 DATE2SEC.h 3 Copyright (C) 2003 Bradford L. Barrett, Paul C. Pratt 4 5 You can redistribute this file and/or modify it under the terms 6 of version 2 of the GNU General Public License as published by 7 the Free Software Foundation. You should have received a copy 8 of the license along with this file; see the file COPYING. 9 10 This file 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 13 license for more details. 14*/ 15 16/* 17 DATE 2(to) SEConds 18 19 convert year/month/day/hour/minute/second 20 to number of seconds since the beginning 21 of 1904, the format for storing dates 22 on the Macintosh. 23 24 The function jdate is from the program Webalizer 25 by Bradford L. Barrett. 26*/ 27 28#ifdef DATE2SEC_H 29#error "header already included" 30#else 31#define DATE2SEC_H 32#endif 33 34/* 35 The function jdate was found at the end of the file 36 webalizer.c in the program webalizer at 37 "www.mrunix.net/webalizer/". 38 Here is copyright info from the top of that file: 39 40 webalizer - a web server log analysis program 41 42 Copyright (C) 1997-2000 Bradford L. Barrett (brad@mrunix.net) 43 44 This program is free software; you can redistribute it and/or modify 45 it under the terms of the GNU General Public License as published by 46 the Free Software Foundation; either version 2 of the License, or 47 (at your option) any later version, and provided that the above 48 copyright and permission notice is included with all distributed 49 copies of this or derived software. 50*/ 51 52/* ************************************************************* */ 53/* */ 54/* JDATE - Julian date calculator */ 55/* */ 56/* Calculates the number of days since Jan 1, 0000. */ 57/* */ 58/* Originally written by Bradford L. Barrett (03/17/1988) */ 59/* Returns an unsigned long value representing the number of */ 60/* days since January 1, 0000. */ 61/* */ 62/* Note: Due to the changes made by Pope Gregory XIII in the */ 63/* 16th Centyry (Feb 24, 1582), dates before 1583 will */ 64/* not return a truely accurate number (will be at least */ 65/* 10 days off). Somehow, I don't think this will */ 66/* present much of a problem for most situations :) */ 67/* */ 68/* Usage: days = jdate(day, month, year) */ 69/* */ 70/* The number returned is adjusted by 5 to facilitate day of */ 71/* week calculations. The mod of the returned value gives the */ 72/* day of the week the date is. (ie: dow = days % 7) where */ 73/* dow will return 0=Sunday, 1=Monday, 2=Tuesday, etc... */ 74/* */ 75/* ************************************************************* */ 76 77LOCALFUNC ui5b jdate(int day, int month, int year) 78{ 79 ui5b days; /* value returned */ 80 int mtable[] = { 81 0, 31, 59, 90, 120, 151, 82 181, 212, 243, 273, 304, 334 83 }; 84 85 /* 86 First, calculate base number including leap 87 and Centenial year stuff 88 */ 89 90 days = (((ui5b)year * 365) + day + mtable[month - 1] 91 + ((year + 4) / 4) - ((year / 100) - (year / 400))); 92 93 /* now adjust for leap year before March 1st */ 94 95 if ((year % 4 == 0) 96 && (! ((year % 100 == 0) && (year % 400 != 0))) 97 && (month < 3)) 98 { 99 --days; 100 } 101 102 /* done, return with calculated value */ 103 104 return (days + 5); 105} 106 107LOCALFUNC ui5b Date2MacSeconds(int second, int minute, int hour, 108 int day, int month, int year) 109{ 110 ui5b curjdate; 111 ui5b basejdate; 112 113 curjdate = jdate(day, month, year); 114 basejdate = jdate(1, 1, 1904); 115 return (((curjdate - basejdate) * 24 + hour) * 60 116 + minute) * 60 + second; 117}