Julian dates
Jo ë l Guillod
joel.guillod at net2000.ch
Fri Apr 16 08:03:35 EDT 2004
For interested parties, here are the 3 base handler/functions I use for
Julian daycount. I have a more elaborated library and could publish it if
anyone is interested (e.g. converting from/to short system date or MySQL
date formats,...).
/** date.julian return the julian count, i.e. days since 24.11.-4713
@param d is the day
@param m is the month
@param y is the year
@returns is the julian count
*/
function date.julian d,m,y
return (1461*(y+4800+(m-14) div 12)) div 4+(367*(m-2-12*((m-14) div 12)))
div 12-(3*((y+4900.0+(m-14) div 12) div 100)) div 4+d-32075
end date.julian
/** date.julian2DMY aJulian, at d, at m, at y
@purpose Set the day, month year according to the julian date aJulian.
*/
on date.julian2DMY aJulian, at d, at m, at y
put aJulian + 68569.0 into l
put ( 4 * l ) div 146097.0 into n
put l - ( 146097.0 * n + 3 ) div 4 into l
put ( 4000.0 * ( l + 1 ) ) div 1461001.0 into i -- (that's 1,461,001)
put l - ( 1461 * i ) div 4 + 31 into l
put ( 80 * l ) div 2447.0 into j
put l - ( 2447.0 * j ) div 80 into d -- day
put j div 11 into l
put j + 2 - ( 12 * l ) into m -- month
put 100 * ( n - 49 ) + i + l into y -- year
end date.julian2DMY
/** get date.julian2DayOfWeek(aJulian)
@purpose Returns the day of the week according to: 1..7 for Sunday..Saturday
@param aJulian is the julian number.
*/
function date.julian2DayOfWeek aJulian
-- // returns 1..7 for Sunday..Saturday
return (aJulian+1) mod 7 + 1
end date.julian2DayOfWeek
--
Hope this help!
Joël Guillod
More information about the use-livecode
mailing list