/* /prjws8/users/michael/aml/ isodate2day.aml /* ------------------------------------------------------------------------ /* This AML was developed as part of the WaterMarque water quality assessment /* project of the Institute for Water Quality Studies /* Department of Water Affairs and Forestry /* Private Bag X313, PRETORIA, 0001 South Africa. /* tel: (012) 808-0374 fax: (012) 808-0338 /* The AML is in the public domain, but copyright is held by the Department /* of Water Affairs and the CSIR. /* Where the AML is used for publication or reporting, /* the source should be acknowledged. /* Michael Silberbauer, October 1993. /* Michael Silberbauer, 2005-03-04 : streamline selections /* Michael Silberbauer, 2005-08-05 : YYYY-MM-DD format /* ------------------------------------------------------------------------ &args Date DayVal &if [null %Date%] &then &return &warning Usage: DATE2DAY \Based on the INFO system which starts in 1801 /* daynumber.aml converts a date in year month day to a day number /* starting at the beginning of the 1800's. It shouldn't be too difficult /* to modify it for earlier dates. /* Define an array to add the correct number of days for each month: &sv DaysPerMonth1 = 0 &sv DaysPerMonth2 = 31 &sv DaysPerMonth3 = 59 &sv DaysPerMonth4 = 90 &sv DaysPerMonth5 = 120 &sv DaysPerMonth6 = 151 &sv DaysPerMonth7 = 181 &sv DaysPerMonth8 = 212 &sv DaysPerMonth9 = 243 &sv DaysPerMonth10 = 273 &sv DaysPerMonth11 = 304 &sv DaysPerMonth12 = 334 /* &type Now calculate the date: &sv Date = [subst %Date% - ,] /*&type %Date% &sv year = [extract 1 %Date%] &sv month = [extract 2 %Date%] &sv day = [extract 3 %Date%] /* &type %year% %month% %day% &if %year% < 1801 &then &type %year% is too small for this system! &sv YY = [calc %year% - 1801] &sv MM = [calc %month%] &sv DD = [calc %day%] /* &type %YY% years since 1801, plus %MM% months and %DD% days... /* calculate the number of leap years before now: &sv LeapYears = %YY% / 4 &sv LeapYears = [truncate %LeapYears%] /* &type Leap Years till now = %LeapYears% /* is this year a leap year? &sv LeapAdd = 0 &if [mod %year% 4] = 0 &then &do &if %year% <> 1900 &then /* Gregory ordained that centuries other than /* millenia are not leaps &do &sv LeapAdd = 1 /* &type This is a Leap Year &end &end /* aml, which has many humps but no c, can't add everything like this: /* &sv Today = (%YY% * 365) + [value DaysPerMonth%MM%] + %DD% + %LeapYears% /* so: &sv YearDays = [calc %YY% * 365] &sv MonthDays = [value DaysPerMonth%MM%] &sv DayDays = [calc %DD% + %LeapYears%] &sv Today = [calc %YearDays% + [calc %MonthDays% + %DayDays%]] &if %MM% > 2 &then &sv Today = [calc %Today% + %LeapAdd%] /* &type %YY%'-'%MM%'-'%DD% = %Today% days &if %year% > 1900 &then; &sv Today = [calc %Today% - 1] /* 1900 was not a leapyear &if ^ [null %DayVal%] &then &do &sv %DayVal% = %Today% /* &type %DayVal% = [value %DayVal%] INFO days &end &if [null %DayVal%] &then &type %Today%