Richard Gaskin  wrote:

"Below are two functions derived from Nelson Zink's code to go from standard
         date format to Julian and back again.  I've modified the code into
         functions, changed the variable names to minimize potential name space
         conflicts, and added local declarations so they'll work with or without
         explicitvars on:
"

Richard,
I too was not satisfied with the way MC handles (or dosen't!) dates-- <1900 and > 
2133--

so I re-did your two functions to be able to verify dates that MC can't handle.

1) The "pDate" variable MUST be a date in long format (E.g.: May 21, 1856) otherwise 
we're looking at
the 20th or 21st Century....Whenever you use convert to dateitems, MC assumes either 
20th or 21st
Century.


2) The "theForm" variable is either "long" or "". If it is empty, the function will 
return the short
date.


------- start of script
function setTheDate pDate,theForm
  put Date2Julian(pDate) into jDate
  put Julian2Date(jDate,theForm) into jDate

  return jDate
end setTheDate

function Date2Julian pDate
  local tYear, tMonth, tDay, aa, bb, cc, dd

  if "/" is in pDate then convert pDate to long date

  put last word of pDate into tYear -- !! catch the year BEFORE the convert.

  convert pDate to dateitems

  put item 2 of pDate into tMonth
  put item 3 of pDate into tDay
  if tMonth < 3 then -- Zeller's Algorithm
    add 12 to tMonth
    subtract 1 from tYear
  end if

  put trunc(tYear/100) into aa
  put (2-aa+trunc(aa/4)) into bb
  put trunc(365.25*tYear) into cc
  put trunc(30.6001*(tMonth+1)) into dd

  return (bb+cc+dd+tDay+1720995)
end Date2Julian

function Julian2Date pJulianDate,theForm
  local tYear, tDay, tMonth, aa, bb, cc, dd, ee, gg
  local monthList, daysOfTheWeek, XX


  ## -- Your language may vary!
  put "January,Feburary,March,April,May,June,July,August," into monthList
  put "September,October,November,December" after monthList
  put "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday" into daysOfTheWeek

  put trunc((pJulianDate-1867216.25)/36524.25) into aa
  put pJulianDate+1+aa-trunc(aa/4) into bb
  Put bb+1524 into cc
  put trunc((cc-122.1)/365.25) into dd
  put trunc(365.25*dd) into ee
  put trunc((cc-ee)/30.6001) into gg

  --��� break into date items
  put cc-ee-trunc(30.6001*gg) into tDay
  if gg<13.5 then put gg-1 into tMonth else put gg-13 into tMonth
  if tMonth>2.5 then put dd-4716 into tYear else put dd-4715 into tYear
  put tYear into cYear

  -- �� calc the day of the week
  -- �� from Zeller's Algorithm

  put cYear div 100 into centuryYear

  put cYear mod 100 into centuryYear1

  put trunc(2.6 * tMonth - 5.39) into mm1
  put trunc(tYear/4) into mm2
  put trunc(cYear/4) into mm3

-- watch out for linewrap below!
  put (mm1 + mm2 + mm3 + tDay + centuryYear1 - (2 * centuryYear)) mod 7 into dayNumber
  add 1 to dayNumber -- Sunday = 0!

  put item dayNumber of daysOfTheWeek into weekDay
  put item tMonth of monthList into thisMonth

  if theForm = "long" then
    return weekDay &", " & thisMonth && tDay & ", " & tYear

  else
    return tMonth &"/"& tDay &"/"& tYear
  end if
end Julian2Date
------- end of script

Hope this helps...

--


Ray G. Miller
-----------
Turtlelips Productions
4009 Everett Ave.
Oakland, CA 94602
MailTo:[EMAIL PROTECTED]
(V) 510.530.1971
(F) 510.482.3491



Archives: http://www.mail-archive.com/[email protected]/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.

Reply via email to