Aloha Sannyasin,

Anyone want to vote for a new standard date format?

YYYY-MM-DD

I prefer a seven-digit Julian representation: YYYYDDD.

Saves one character per date, and the logic for calculating the # of days between two dates and calculating the date x days before or after a given date is a bit simpler, me thinks.

Hi Charles,

It would be *great* to have a
smart function like that, that would take the whole range of formats
various users might type into a field. (Anybody got one?)

I come from a multi-user background where one expects everyone will use the same date format when entering dates in the same application; so my date routines can support any Control Panel system date format currently in effect, but mark any date that is not system compliant as invalid.

Following are some of the Julian date routines in Serendipity Library <http:wecode.org/serendipity/>:

function systemDateToJulian theDate -- 16 Mar 04:RCC
get validDate(theDate) -- returns "true" & return & the dateItems if date is valid per
  -- the computer's system date format
if word 1 of it then return dateItemsToJulian(line 2 of it) else return empty
end systemDateToJulian

function dateItemsToJulian theDateItems -- 17 Mar 04:RCC
  put item 1 of theDateItems into theJulianDate
  put 31 into monthLength[1]
  if leapYear(theJulianDate) then put 29 into monthLength[2]
  else put 28 into monthLength[2]
  put 31 into monthLength[3]
  put 30 into monthLength[4]
  put 31 into monthLength[5]
  put 30 into monthLength[6]
  put 31 into monthLength[7]
  put 31 into monthLength[8]
  put 30 into monthLength[9]
  put 31 into monthLength[10]
  put 30 into monthLength[11]
  put 31 into monthLength[12]
  multiply theJulianDate by 1000
  get (item 2 of theDateItems)-1
  repeat with x = 1 to it
    add monthLength[x] to theJulianDate
  end repeat
  add item 3 of theDateItems to theJulianDate
  return justifyString(theJulianDate,7,"left","0") -- for centuries < 1000
end dateItemsToJulian

function julianToSystemDate theJulianDate -- 16 Mar 04:RCC
  get julianToDateItems(theJulianDate)
return formatDate(item 1 of it,item 2 of it,item 3 of it,true) -- formats to system date
end julianToSystemDate

function julianToDateItems theJulianDate -- 7 Apr 04:RCC
  put 0 into monthEnd[0]
  put 31 into monthEnd[1]
  put 59 into monthEnd[2]
  put 90 into monthEnd[3]
  put 120 into monthEnd[4]
  put 151 into monthEnd[5]
  put 181 into monthEnd[6]
  put 212 into monthEnd[7]
  put 243 into monthEnd[8]
  put 273 into monthEnd[9]
  put 304 into monthEnd[10]
  put 334 into monthEnd[11]
  put 365 into monthEnd[12]
  put (char 1 to -4 of theJulianDate) into theYear
  put char -3 to -1 of theJulianDate into julianDays
  if julianDays < 1 then return empty
  if leapYear(theYear) then
    if julianDays = 60 then return itemsWithDay(theYear&",2,29,0,0,0,0")
    else if julianDays > 60 then subtract 1 from julianDays
  end if
  if julianDays > 365 then return empty
  repeat with x = 1 to 12
    if julianDays <= monthEnd[x] then
      put x into theMonth
      put julianDays - monthEnd[x-1] into theDays
      return itemsWithDay(theYear&comma&theMonth&comma&theDays&",0,0,0,0")
-- itemsWithDay returns the constructed dateItems string with the correct day of
--   week represented by the first 3 items
    end if
  end repeat
end julianToDateItems

Rob Cozens

"We are living on a dying planet.
 We're killing everything that's alive.
 And anyone who tries to deny it wears a tie,
 and gets paid to lie."

-- Joe Walsh, from "Songs for a Dying Planet"
_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to