cmp8163@information-systems.east-anglia.ac.uk ("P.N.J. Vlietstra") (11/10/90)
Does anyone have a PD program (or tell me where to get it through FTP) which takes the system time obtained from a call to an Intuition Library Function (can't remember now what the function is called precisely) and converts that (taking into account Summer time, leap years, etc.) to a date and time in ASCII or integer format ? The library function only returns seconds elapsed since January 1, 1978, I believe. A friend of mine would like to have the source in Benchm*rk Modula-2 or,if that's not possible, in C. Thanks, -Peter Vlietstra cmp8163@sys.uea.ac.uk University of East Anglia Norwich England.
thad@cup.portal.com (Thad P Floryan) (11/10/90)
cmp8163@information-systems.east-anglia.ac.uk ("P.N.J. Vlietstra") in <3936.9011091814@subnode.sys.uea.ac.uk> writes: Does anyone have a PD program (or tell me where to get it through FTP) which takes the system time obtained from a call to an Intuition Library Function (can't remember now what the function is called precisely) and converts that (taking into account Summer time, leap years, etc.) to a date and time in ASCII or integer format ? The library function only returns seconds elapsed since January 1, 1978, I believe. A friend of mine would like to have the source in Benchm*rk Modula-2 or,if that's not possible, in C. Enclosed is a routine I've posted several times before, and it was to appear in Rob Peck's updated book ... it may still. Thad Floryan [ thad@cup.portal.com (OR) ..!sun!portal!cup.portal.com!thad ] -------------------- begin enclosure -------------------- From: thad@cup.portal.com Newsgroups: comp.sys.amiga.tech Subject: Re: Decoding a DateStamp Message-ID: <5276@cup.portal.com> Date: 10 May 88 09:20:41 GMT References: <24309@bbn.COM> The following code may be useful to you. It's one of several hundreds of kwik'n'dirty throwaways I did back in '85 when testing every documented feature of the Amiga. The "basic" code also works fine on DEC-20, Vax, AT&T UNIX PC, C64/C128, and every other system I've tried it on. Originally compiled this with Lattice 3.02; to compile with any recent Manx: CLI> cc +L dater CLI> ln dater -lc32 Feel welcome to use this example for your own learning; I'm intending this (along with my complete date arithmetic package) to be part of an article I intend completing (Real Soon Now :-) along with examples in C, assembler, Fortran, AmigaBasiC, Modula-2 and Pascal. This specific example has worked perfectly thru AmigaDOS 1.0, 1.1, and 1.2 (and presumably 1.3 and beyond). ----------cut 'ere---------- /* DATER.C Check out the DateStamp AmigaDOS system function * * see page 2-15 in the AmigaDOS Developer's Manual for more info */ struct DS { /* DateStamp structure */ long NDays; /* Days from Jan. 1, 1978 (a Sunday) */ long NMinutes; /* Minutes into the current day */ long NTicks; /* Clock ticks (1/50 sec = 1 tick) in current second */ }; static char *wkdays[] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; static char *mthnam[] = {"","JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"}; main() { void DateStamp(), YrMoDa(); struct DS datime; long month, day, year, hour, minute, second; DateStamp(&datime); printf("Days since 1-JAN-78 = %d\n", datime.NDays); printf("Minutes into today = %d\n", datime.NMinutes); printf("1/50 secs in minute = %d\n", datime.NTicks); YrMoDa(datime.NDays, &year, &month, &day); printf("\nTherefore today is "); printf("%s ", wkdays[datime.NDays % 7]); printf("%d-%s-%d", day, mthnam[month], year); hour = datime.NMinutes / 60; minute = datime.NMinutes % 60; second = datime.NTicks / 50; printf(" %2d:%02d:%02d\n", hour, minute, second); exit(0); } /****************************** YrMoDa ********************************** * * Extracts the component month, day and year from an AmigaDOS * internal `day number' based from Jan.1, 1978. * * The calculations herein use the following assertions: * * 146097 = number of days in 400 years per 400 * 365.2425 = 146097.00 * 36524 = number of days in 100 years per 100 * 365.2425 = 36524.25 * 1461 = number of days in 4 years per 4 * 365.2425 = 1460.97 * * Thad Floryan, 12-NOV-85 */ #define DDELTA 722449 /* days from Jan.1,0000 to Jan.1,1978 */ static int mthvec[] = {-1, -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364}; void YrMoDa(intdat, yr, mo, da) long intdat; /* I: AmigaDOS format, days since 1-JAN-78 */ long *yr; /* O: resultant year in form YYYY */ long *mo; /* O: resultant month in form MM */ long *da; /* O: resultant day of month in form DD */ { register long jdate, day0, day1, day2, day3; jdate = intdat + DDELTA; /* adjust internal date to Julian */ *yr = (jdate / 146097) * 400; day0 = day1 = jdate %= 146097; *yr += (jdate / 36524) * 100; day2 = day1 %= 36524; *yr += (day2 / 1461) * 4; day3 = day1 %= 1461; *yr += day3 / 365; *mo = 1 + (day1 %= 365); *da = *mo % 30; *mo /= 30; if ( ( day3 >= 59 && day0 < 59 ) || ( day3 < 59 && (day2 >= 59 || day0 < 59) ) ) ++day1; if (day1 > mthvec[1 + *mo]) ++*mo; *da = day1 - mthvec[*mo]; } /* end of DATER.C */ -------------------- end of enclosure --------------------