" > BLib.Date 1.03 13-Mar-2007 % Time and date support functions : (C)J.G.Harston, may be freely used and redistributed (K v1.00 12-Sep-1992 JGH: FromOrd(), DayOfWeek(), Day(), Mon() functions 26 v1.01 18-Feb-1994 JGH: ToOrd() and Since() added <- v1.02 17-Sep-2005 JGH: ToOrd() debugged FC v1.03 13-Mar-2007 JGH: Added [To|From][Day|Month]() functions P: Z: d6 FNDay(day%) - return 3-char day of week string n0 FNMon(month%) - return 3-char month string x6 ------------------------------------------------ : 4ݤDay(A%):="000SunMonTueWedThuFriSat",A%*3+1,3) LݤMon(A%):="000JanFebMarAprMayJunJulAugSepOctNovDecDDDEEEFFF",A%*3+1,3) : : B FNDate_FromDay(A$) - return day number for supplied string D FNDate_FromMonth(A$) - return month number for supplied string D -------------------------------------------------------------- : !ݤDate_FromDay(A$):A$=uc(A$) 'A%="SUNMONTUEWEDTHUFRISAT",A$,3)) (A%-1)3=0:=A%3+1 =0 : #ݤDate_FromMonth(A$):A$=uc(A$) 6A%="JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC",A$,3)) (A%-1)3=0:=A%3+1 =0 ": ,: 6D FNDate_ToDay(day%) - return full-length day of week string @> FNDate_ToMonth(month%) - return full-length month string JD -------------------------------------------------------------- T: ^ݤDate_ToDay(A%) h[="SunMonTuesWednesThursFriSatur","01040711172225",A%*2-1,2),"3346535",A%,1))+"day" r: |ݤDate_ToMonth(A%) ="JanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember","010816212629333743525967",A%*2-1,2),"785534469788",A%,1)) : : P FNDate_DayOfWeek(day%,month%,year%) - return day of week for supplied date @ 1=Sunday, 7=Saturday P -------------------------------------------------------------------------- : (ݤDate_DayOfWeek(d%,m%,y%):y%=y%400 q=(y%*365.25+m%*30+d%+"120112234455",m%,1)+((y%4)=0)-((y%-1)100)-(m%>2((y%4)=0(y%100)<>0y%=0))+3)7+1 : : K PROCDate_FromOrd - convert time and date to 5-byte centi-second count * On entry: mem%->five bytes of memory , day, month, year of the date A hours, minutes, seconds, centiseconds of the time I On exit: mem% to mem%+4 containes five-byte centisecond time since &' 00:00:00 on 1-Jan-1900. 0K --------------------------------------------------------------------- :: D;Date_FromOrd(mem%,d%,m%,y%,hr%,mn%,sc%,cs%):y%=y%400 Nqd%=y%*365.25+m%*30+d%+"120112234455",m%,1)+((y%4)=0)-((y%-1)100)-(m%>2((y%4)=0(y%100)<>0y%=0))+36493 Xd%>146066:d%=d%-146097 b=d%=d%*&41EB:mem%!1=d%+d%:d%=((hr%*60+mn%)*60+sc%)*100+cs% l#?mem%=d%:mem%!1=mem%!1+d%256: v: : I PROCDate_ToOrd - convert 5-byte centi-second count to time and date K On entry: mem%->five bytes of memory containing five-byte centisecond 2 time since 00:00:00 on 1-Jan-1900. , On exit: day, month, year of the date A hours, minutes, seconds, centiseconds of the time K --------------------------------------------------------------------- : $Date_ToOrd(mem%): A%,B%,C%,D% @year%=0:month%=0:day%=0:hour%=0:minute%=0:second%=0:centi%=0 -mem%!1<0:: Problems with negatives ATM FD%=mem%!1&83D6+2447065:C%=mem%?0+256*(mem%!1&83D6):centi%=C%100 >C%=C%100:second%=C%60:C%=C%60:minute%=C%60:hour%=C%60 8B%=((D%*4+3)146097-4)+3:C%=B%14614*5+2:D%=D%*4+3  .A%=C%153+2:day%=C%1535+1:month%=A%12+1 *year%=D%146097*100+B%1461+A%12-4800   *: 4: >> FNDate_Since - return number of days since a past date HI On entry: td%, tm% and ty% should be set to today's date, month and RI year and pd%, pm% and py% should be set to the past date, \ month and year. f( Requires X%->5-byte control block pI ------------------------------------------------------------------- z: 1ݤDate_Since(td%,tm%,ty%,pd%,pm%,py%): past% 4Date_FromOrd(X%,pd%,pm%,py%,0,0,0,0):past%=X%!1 =Date_FromOrd(X%,td%,tm%,ty%,0,0,0,0):=(X%!1-past%)&83D6 :