harmonv
Oct 22, 2006
- "added Gregorian date and day routines"
Liberty Basic Day and Date Routines
LB day-of-week conversion
This routine uses LB's built-in date$() function. In the LB universe, day 0 was Jan 1, 1901 and dates before 1/1/1901 return negative numbers.
It will accept 1- or 2-digit numbers for the month and day and 1, 2, 3 or 4-digit numbers for the year. Years from 0 to 99 are assumed as 2000 to 2099. It will also accept fully typed month names or 3-letter abbreviations.
Some examples: Jul 4, 06 -- July 04, 2006 -- 7/4/6 -- 07/04/2006
Be aware that negative years are incorrectly handled as positive, so LB's date$() function can not be relied upon for any date earlier than Jan 1, 100.
' Return day-of-week for d$function dayofweek$(dt$)
day =date$(dt$)mod7+7' +7 for dates before Jan 1, 1901selectcase(day mod7)case0: d$ ="Tuesday"case1: d$ ="Wednesday"case2: d$ ="Thursday"case3: d$ ="Friday"case4: d$ ="Saturday"case5: d$ ="Sunday"case6: d$ ="Monday"endselect
dayofweek$ = d$
endfunction
Gregorian Year, Month, Day to Julian Day #
' Convert Gregorian year,month,day to Julian Day #function G2Jd(yr,mo,dy)
a =int((14-mo)/12)
y = yr +4800- a
m = mo +12*a -3
G2Jd = dy +int((153*m+2)/5)+365*y+int(y/4)-int(y/100)+int(y/400)-32045endfunction
Julian Day to Gregorian Year, Month, Day
' Julian day to Gregorian datefunction Jd2G(jd, byref yr, byref mo, byref dy)
a = jd +32044
b =int((4*a+3)/146097)
c = a -int((146097*b)/4)
d =int((4*c+3)/1461)
e = c -int(1461*d/4)
m =int((5*e+2)/153)
dy = e -int((153*m+2)/5)+1
mo = m +3-12*int(m/10)
yr =100*b + d -4800+int(m/10)endfunction
Gregorian Year, Month, Day to day-of-week
' Gregorian date to day-of-week (0=Sun, 1=Mon, ...)function G2dow(yr,mo,dy)
a =int((14-mo)/12)
m = mo +12*a -2
y = yr - a
G2dow =(dy + y +int(y/4)-int(y/100)+int(y/400)+int(31*m/12))mod7endfunction
The calculations for the Gregorian date and day routines are from Claus Tøndering's excellent Calendar FAQ page at http://www.tondering.dk/claus/calendar.html
They can be freely distributed for all non-commerical uses.
Liberty Basic Day and Date Routines
LB day-of-week conversion
This routine uses LB's built-in date$() function. In the LB universe, day 0 was Jan 1, 1901 and dates before 1/1/1901 return negative numbers.It will accept 1- or 2-digit numbers for the month and day and 1, 2, 3 or 4-digit numbers for the year. Years from 0 to 99 are assumed as 2000 to 2099. It will also accept fully typed month names or 3-letter abbreviations.
Some examples: Jul 4, 06 -- July 04, 2006 -- 7/4/6 -- 07/04/2006
Be aware that negative years are incorrectly handled as positive, so LB's date$() function can not be relied upon for any date earlier than Jan 1, 100.
Gregorian Year, Month, Day to Julian Day #
Julian Day to Gregorian Year, Month, Day
Gregorian Year, Month, Day to day-of-week
The calculations for the Gregorian date and day routines are from Claus Tøndering's excellent Calendar FAQ page at http://www.tondering.dk/claus/calendar.html
They can be freely distributed for all non-commerical uses.