REVO2700 DateTime2@[vrctRevID 1249863732cDefaultStackDateTime{--> all handlers -- englishToSystemDate([pDate], [showLong]) -- -- englishToSystemDate() -- englishToSystemDate("12/31/2003") -- englishToSystemDate(,showLong) -- -- Converts English date (m/d/y) to the system date format. -- If no date is specified, it will return the current date in the system format. -- The optional 2nd parameter allows specification of long or short date -- with the short format being the default. -- function englishToSystemDate pDate, pUseLong if pDate is empty then put the english date into pDate if pUseLong = "showLong" then convert pDate from english date to long system date else convert pDate from english date to short system date end if return pDate end englishToSystemDate -- systemToEnglishDate([pDate], [showLong]) -- -- systemToEnglishDate() -- systemToEnglishDate(,showLong) -- -- Converts the system date to the English date format (m/d/y). -- If no date is specified, it will return the current date in English format. -- The optional 2nd parameter allows specification of long or short date -- with the short format being the default. -- function systemToEnglishDate pDate, pUseLong if pDate is empty then put the system date into pDate if pUseLong = "showLong" then convert pDate from system date to long english date else convert pDate from system date to short english date end if return pDate end systemToEnglishDate -- isLeapYear([pYear]) -- -- isLeapYear() -- isLeapYear(2000) -- -- Returns true if the specified year is a leap year and false if not. -- If no year is specified, it will calculate for the current year. -- function isLeapYear pYear if pYear is empty or pYear is not a number then put the seconds into tNow convert tNow to dateItems put item 1 of tNow into pYear end if if (pYear mod 400 = 0) or (pYear mod 100 <> 0) and (pYear mod 4 = 0) then return true else return false end if end isLeapYear -- totalDaysInYear([pYear]) -- -- totalDaysInYear() -- totalDaysInYear(2001) -- -- Clever function for determining the number of days in a year -- allowing for leap years. It works by setting the dateItems to -- the day before the 1st March. When converted back to date format, -- the internal handlers automatically convert this to 29th or 28th February -- allowing you to check for a leap year. -- The single optional parameter is a year. If none is specified, the current year is used. -- Thanks to ric Chatonet for this function. -- function totalDaysInYear pYear if pYear is empty or pYear is not a number then put the seconds into tDate convert tDate to dateItems put 3 into item 2 of tDate put 0 into item 3 of tDate else put pYear & "3,0,12,0,0,0" into tDate end if convert tDate to dateItems if item 3 of tDate = 29 then return "366" else return "365" end totalDaysInYear -- numericDate([pDate]) -- -- numericDate() -- numericDate("12/31/03") -- -- Returns the date in yyyymmdd format for the specified date. -- If no date is specified, it will return the current year. -- This has the advantage of being sortable both numerically and alphabetically. -- If supplied, the date must be in English format (use the systemToEnglishDate function if necessary). -- function numericDate pDate if pDate is empty or pDate is not a date then put the short english date into pDate convert pDate from short english date to dateItems put item 2 of pDate into tMonth if tMonth < 10 then put "0" before tMonth put item 3 of pDate into tDay if tDay < 10 then put "0" before tDay return item 1 of pDate & tMonth & tDay end numericDate -- yearNum([pDate]) -- -- yearNum() -- yearNum("6/3/03") -- -- Returns the 4 digit year number for the specified date. -- If no date is specified, it will return the current year. -- If supplied, the date must be in English format (use the systemToEnglishDate function if necessary). -- function yearNum pDate if pDate is empty or pDate is not a date then put the short english date into pDate convert pDate from short english date to dateItems return item 1 of pDate end yearNum -- monthName([pMonthNum], [abbrev], [useSystem]) -- -- monthName() -- monthName(7) -- monthName(,abbrev) -- monthName(3,useSystem) -- -- Returns the month name for a specific month number. -- If no month is specified, it will return the current month's name. -- The other parameters allows specification of long or short names -- with the long names being the default and specification of system or default names -- with the system names being the default. The order of these extra parameters does -- not matter, but the month number must be first. If no month number is specified, -- an empty parameter must be first. -- function monthName pMonthNum if pMonthNum is empty then put the seconds into tNow convert tNow to dateItems put item 2 of tNow into pMonthNum else if pMonthNum is not a number then return pMonthNum end if put false into pAbbrev put false into pUseSystemNames put the paramcount into pCount repeat for each item p in the params if p contains "abbrev" then put true into pAbbrev if p contains "useSystem" then put true into pUseSystemNames end repeat if pAbbrev = true then if pUseSystemNames = false then return line pMonthNum of the abbrev monthnames else return line pMonthNum of the abbrev system monthnames end if else if pUseSystemNames = false then return line pMonthNum of the monthnames else return line pMonthNum of the system monthnames end if end if end monthName -- monthNum([pMonth]) -- -- monthNum() -- monthNum("Dec") -- monthNum("January") -- -- Returns the month number for a specific month name, with either long or short month names being allowed. -- It will work if the system names or the default names for the months are used. -- If no month is specified, it will return the current month's number. -- If no match is found, the result will be 0. -- function monthNum pMonth if pMonth is empty then put the seconds into tNow convert tNow to dateItems return item 2 of tNow else get lineoffset(pMonth, the abbrev system monthNames) if it = 0 then get lineoffset(pMonth, the system monthNames) if it = 0 then get lineoffset(pMonth, the abbrev monthNames) if it = 0 then get lineoffset(pMonth, the monthNames) return it end if end monthNum -- daysInMonth([pMonth], [pYear]) -- -- daysInMonth() -- daysInMonth("Dec") -- daysInMonth(2,2000) -- -- Returns the number of days in a specific month. -- The month can be entered as a number or a name with either long or short month names being allowed. -- System or default month names are both allowed. -- If no month is specified, it will return the current month's number. -- If a name is used, this function calls the monthNum() function, so don't separate them if copying this script into another stack. -- function daysInMonth pMonth, pYear if pMonth is empty or pYear is empty then put the seconds into tNow convert tNow to dateItems if pMonth is empty then put item 2 of tNow into pMonth if pYear is empty then put item 1 of tNow into pYear end if if pMonth is not a number then put monthNum(pMonth) into pMonth if (pMonth is in "1,3,5,7,8,10") or (pMonth = 12) then return 31 else if (pMonth is in "4,6,9,11") then return 30 else if (pYear mod 400 = 0) or (pYear mod 100 <> 0) and (pYear mod 4 = 0) then return 29 -- leap year else return 28 end daysInMonth -- weekNum([pDate]) -- -- weekNum() -- weekNum("12/31/2002") -- -- Returns the absolute week number for a specific date. -- If supplied, the date must be in English format (use the systemToEnglishDate function if necessary). -- If no date is specified, the current week number is returned -- This is not the ISO week number where week 1 is the week beginning on a Monday that contains -- 4th January, but the absolute week where week 1 starts on January 1st. -- December 31st will always be in week 53 and December 30th will vary with leap years. -- function weekNum pDate if pDate is empty or pDate is not a date then put the short english date into pDate put pDate into startYearDate set itemdelimiter to "/" put 1 into item 1 of startYearDate put 1 into item 2 of startYearDate convert pDate from short english date to seconds convert startYearDate from short english date to seconds put pDate - startYearDate into secsThisYear put secsThisYear / (24*60*60) into daysThisYear return (daysThisYear div 7) + 1 end weekNum -- weekNumISO([pDate], [pBeginningDay]) -- -- weekNumISO() -- weekNumISO("30/3/2002") -- weekNumISO(,"Sunday") -- weekNumISO("12/31/2000") -- weekNumISO("12/31/2000", "Sunday") -- -- Returns the number of the current week according to ISO: -- first Thursday of the year is always in the first week of the year. -- If supplied, the date must be in English format (use the systemToEnglishDate function if necessary). -- If no date is specified, the current date is used. -- The second optional parameter is "Sunday" or "Monday" and indicates the first week day displayed. -- If no beginning date is specified, "Monday" is used as the default (ISO standard). -- This function calls the dayNum() function, so don't separate them if copying this script into another stack. -- -- Thanks to ric Chatonet for this function. -- function weekNumISO pDate, pBeginningDay if pBeginningDay <> "Sunday" then put "Monday" into pBeginningDay if pDate is empty or pDate is not a date then put the short english date into pDate -- computing the number of days in current week: convert pDate from short english date to dateItems put last item of pDate into tDay if pBeginningDay = "Sunday" then put tDay into tNumOfDaysInCurrentWeek else if tDay = 1 then put 7 into tNumOfDaysInCurrentWeek else put tDay - 1 into tNumOfDaysInCurrentWeek end if -- computing the days of first & last day of year put pDate into firstDayOfYear put 1 into item 2 of firstDayOfYear put 1 into item 3 of firstDayOfYear convert firstDayOfYear to dateItems put last item of firstDayOfYear into firstDay put pDate into lastDateOfYear put 12 into item 2 of lastDateOfYear put 31 into item 3 of lastDateOfYear convert lastDateOfYear to dateItems put last item of lastDateOfYear into lastDay -- computing the number of days in first week of the year: if pBeginningDay = "Sunday" then put (firstDay is not in "67") into tThursdayIsInFirstWeek else put (firstDay is not in "167") into tThursdayIsInFirstWeek end if if pBeginningDay = "Sunday" then put 8 - (firstDay) into tNumOfDaysInFirstWeek else if firstDay = 1 then put 1 into tNumOfDaysInFirstWeek else put 9 - firstDay into tNumOfDaysInFirstWeek end if -- computing the week number and returning the result: put pDate into tEnglishDate convert tEnglishDate from dateItems to short english date put dayNum(tEnglishDate) into tDayNum if tThursdayIsInFirstWeek then if tDayNum <= tNumOfDaysInFirstWeek then return "1" else if (tDayNum > tNumOfDaysInFirstWeek) and \ (tDayNum <= tNumOfDaysInFirstWeek + tNumOfDaysInCurrentWeek) then return "2" else put ((tDayNum - (tNumOfDaysInFirstWeek + tNumOfDaysInCurrentWeek)) / 7) + 2 into tWeekNum -- check for going over to the next year if tWeekNum = 53 then -- if last day of the year is after Thursday, go to next year if lastDay < 5 then return 1 else return 53 else if tWeekNum = 54 then return 1 else return tWeekNum end if end if else if tDayNum <= tNumOfDaysInFirstWeek then if (firstDay < 4 and pBeginningDay = "Sunday") or \ (tDayNum <> 1 and tDayNum < 4 and pBeginningDay = "Monday") then return 1 else subtract 1 from item 1 of lastDateOfYear return weekNum(lastDateOfYear, pBeginningDay) -- recursive end if else if (tDayNum > tNumOfDaysInFirstWeek) and \ (tDayNum <= tNumOfDaysInFirstWeek + tNumOfDaysInCurrentWeek) then return "1" else return ((tDayNum - (tNumOfDaysInFirstWeek + tNumOfDaysInCurrentWeek)) / 7 ) + 1 end if end weekNumISO -- dayName([pDate], [abbrev], [useSystem]) -- -- dayName() -- dayName("9/30/20") -- dayName(,abbrev) -- dayName(,useSystem) -- -- Returns the weekday name for a specific date. -- If no date is specified, it will use the current date. -- If supplied, the date must be in English format (use the systemToEnglishDate function if necessary). -- The other parameters allows specification of long or short names -- with the long names being the default and specification of system or default names -- with the system names being the default. The order of these extra parameters does -- not matter, but the date must be first. If no date is specified, -- an empty parameter must be first. -- function dayName pDate if pDate is empty then put the short english date into pDate else if pDate is not a date then return empty put false into pAbbrev put false into pUseSystemsNames put the paramcount into pCount repeat for each item p in the params if p contains "abbrev" then put true into pAbbrev if p contains "useSystem" then put true into pUseSystemsNames end repeat convert pDate from short english date to dateItems put last item of pdate into dayNum if pAbbrev = true then if pUseSystemsNames = false then return line dayNum of the abbrev weekdaynames else return line dayNum of the abbrev system weekdaynames end if else if pUseSystemsNames = false then return line dayNum of the weekdaynames else return line dayNum of the system weekdaynames end if end if end dayName -- dayNum -- -- dayNum() -- dayNum("12/31/2004") -- -- Returns the day number for a specific date. -- If no date is specified, it will use the current date. -- If supplied, the date must be in English format (use the systemToEnglishDate function if necessary). -- Thanks to ric Chatonet for this function. -- function dayNum pDate if pDate is empty or pDate is not a date then put the short english date into pDate put pDate into tJanuaryFirst convert tJanuaryFirst from short english date to dateItems put 1 into item 2 of tJanuaryFirst put 1 into item 3 of tJanuaryFirst convert tJanuaryFirst to seconds convert pDate to seconds return round((pDate - tJanuaryFirst) / 86400) + 1 end dayNum -- daysBetween(date1, [date2]) -- -- daysBetween("9/28/03") -- daysBetween("1/1/2002", "1/1/2003") -- -- Returns the number of days between 2 dates. -- If only one date is specified, it will use the current date for the second. -- The dates must be in English format (use the systemToEnglishDate function if necessary). -- It doesn't matter whether the most recent date is first or last. -- function daysBetween pDate1, pDate2 if pDate2 is empty then put the short english date into pDate2 if pDate1 is not a date or pDate2 is not a date then return empty convert pDate1 from short english date to dateItems convert pDate2 from short english date to dateItems repeat with i = 4 to 7 put 0 into item i of pDate1 put 0 into item i of pDate2 end repeat convert pDate1 from dateItems to seconds convert pDate2 from dateItems to seconds put abs(pDate1 - pDate2) into tDiff return tDiff / (60 * 60 * 24) end daysBetween -- monthNumber -- -- monthNumber() -- monthNumber("12/31/2004") -- monthNumber() - monthNumber("1/1/2004") -- -- returns a numeric value for the months in a given date so month comparisons can be made -- If no date is specified, it will use the current date. -- If supplied, the date must be in English format (use the systemToEnglishDate function if necessary). -- function monthNumber pDate if pDate is empty or pDate is not a date then put the short english date into pDate convert pDate to dateItems put item 1 of pDate into tYears put item 2 of pDate into tMonths put item 3 of pDate into tDay if tDay > 15 then add 1 to tMonths return (tYears * 12) + tMonths end monthNumber -- timeZone() -- -- timeZone() -- -- Returns the time zone according to the current system settings -- using +/-hhmm format. -- function timeZone put the internet date into tNow put last word of tNow into tZone return tZone end timeZone -- militaryClock([showSecs]) -- -- militaryClock() -- militaryClock(showSecs) -- -- Returns the time in 24 hour format, regardless of current system settings. -- The normal preferences will remain unchanged. -- The optional parameter can be used to specify that the time be shown with seconds, -- without seconds is the default. -- function militaryClock pShowSeconds put the twelvehourtime into oldSet set the twelvehourtime to false if pShowSeconds = "showSecs" then put the long system time into tNow else put the system time into tNow end if set the twelvehourtime to oldSet return tNow end militaryClock -- twelveHourClock([showSecs]) -- -- twelveHourClock() -- twelveHourClock(showSecs) -- -- Returns the time in 12 hour format showing am or pm, regardless of current system settings. -- The normal preferences will remain unchanged. -- The optional parameter can be used to specify that the time be shown with seconds, -- without seconds is the default. -- function twelveHourClock pShowSeconds put the twelvehourtime into oldSet set the twelvehourtime to true if pShowSeconds = "showSecs" then put the long system time into tNow else put the system time into tNow end if set the twelvehourtime to oldSet return tNow end twelveHourClock -- titleCase(pString) -- -- titleCase("wednesday") -- titleCase("janvier") -- -- Changes the first letter of the supplied string to uppercase. -- Apparently, the system monthNames and system weekdayNames in some -- languages, return the names all in lower case, which may need correcting. -- function titleCase pString put toupper(char 1 of pString) into char 1 of pString return pString end titleCase -- dateOfEaster(pYear) -- -- dateOfEaster() -- dateOfEaster(2000) -- dateOfEaster(1500) -- -- This funcion calculates the date of Easter for a given year. -- If no year is specified, the current year is used. -- It cannot calculate Easter for years before 1583, so will return empty for any years earlier than that. -- The date is returned in short English format (use the systemToEnglishDate function to convert if necessary). -- function dateOfEaster pYear if pYear is empty or pYear is not a number then put the seconds into tNow convert tNow to dateItems put item 1 of tNow into pYear end if if pYear < 1583 then return empty put 0 into wCorrection if( pYear < 1700 ) then put 4 into wCorrection else if pYear < 1800 then put 5 into wCorrection else if pYear < 1900 then put 6 into wCorrection else if pYear < 2100 then put 0 into wCorrection else if pYear < 2200 then put 1 into wCorrection else if pYear < 2300 then put 2 into wCorrection else if pYear < 2500 then put 3 into wCorrection put (19 * (pYear mod 19) + 24) mod 30 into wDay put 22 + wDay + ((2 * (pYear mod 4) + 4 * (pYear mod 7) + 6 * wDay + 5 + wCorrection) mod 7) into wDay -- jump to next month if wDay > 31 then put 4 into wMonth subtract 31 from wDay else put 3 into wMonth end if return wMonth & "/" & wDay & "/" & pYear end dateOfEaster -- relativeDate(pIndex, pDay, pMonth, pYear) -- -- relativeDate("First", "Tues", "November", "2004") -- relativeDate("Last", "Wednesday", "January", "2000") -- relativeDate(2, "Sunday", 5, "2002") -- -- This function calculates exact dates from relative dates -- like "the last Monday in May 2000" or "the 2nd Saturday in October 2004". -- pIndex can be: First, Second, Third, Fourth, Last -- or +1, +2, +3, +4, +5, -1 (the + is optional). -- pDay is a day name in long or abbreviated system form. -- pMonth can be a number or a month name and pYear must be a number. -- The resulting date is returned in short English format (use the systemToEnglishDate function to convert if necessary). -- function relativeDate pIndex, pDay, pMonth, pYear -- extract the day name & convert to a number put char 1 to 3 of pDay into tDayName put the abbrev system weekdaynames into tDayList get lineoffset(tDayName, tDayList) if it = 0 then return empty put it into tDayNum if pMonth is not a number then put monthNum(pMonth) into pMonth if char 1 of pIndex = "+" then delete char 1 of pIndex -- find first whatever day in the month put pMonth & "/1/" & pYear into firstDate convert firstDate from short english date to dateItems put last item of firstDate into firstDayNum put tDayNum - firstDayNum into dayDiff if dayDiff < 0 then add 7 to dayDiff add dayDiff to item 3 of firstDate convert firstDate to seconds convert firstDate to dateItems -- add weeks as necessary switch pIndex case "First" case "1" break case "Second" case "2" add 7 to item 3 of firstDate break case "Third" case "3" add 14 to item 3 of firstDate break case "Fourth" case "4" add 21 to item 3 of firstDate break case "Fifth" case "5" add 28 to item 3 of firstDate break case "Last" case "-1" -- try week 5 and if that doesn't work, use week 4 put firstDate into testDate add 28 to item 3 of testDate convert testDate to seconds convert testDate to dateItems if item 2 of testDate = pMonth then put testDate into firstDate else add 21 to item 3 of firstDate end if break default return empty end switch convert firstDate to seconds convert firstDate to dateItems put item 2 of firstDate into newM put item 3 of firstDate into newD return pMonth & "/" & newD & "/" & pYear end relativeDate -- dateTimeToJulian(pYear, pMonth, pDate, [pHour], [pMins], [pSecs]) -- -- dateTimeToJulian() -- dateTimeToJulian(2004,3,22) -- dateTimeToJulian(2004,3,22,12,2) -- dateTimeToJulian(2004,3,22,12,5,45) -- -- This function returns the date and time in Julian date format. -- If no date is specified, it will use the current date. -- If supplied, the date must be in date items format: year, month, day, hour, minutes, seconds -- This is because the internal date conversions may not work for early dates. -- The time parameters are optional and seconds need not be specified. -- -- Julian dates (abbreviated JD) are simply a continuous count of days and fractions -- since noon Universal Time on January 1, 4713 BCE (on the Julian calendar). -- Almost 2.5 million days have transpired since this date. -- Julian dates are widely used as time variables within astronomical software. -- Typically, a 64-bit floating point (double precision) variable can represent -- an epoch expressed as a Julian date to about 1 millisecond precision. -- Note that the time scale that is the basis for Julian dates is Universal Time, -- and that 0h UT corresponds to a Julian date fraction of 0.5. -- -- It is assumed that 7-day weeks have formed an uninterrupted sequence since ancient times. -- Thus, the day of the week can be obtained from the remainder of the division of -- the Julian date by 7. -- -- This function is copyright 2004 Mark Wieder and Ah, Software -- function dateTimeToJulian pYear, pMonth, pDate, pHour, pMins, pSecs if the paramcount < 3 then put the seconds into tNow convert tNow to dateItems put item 1 of tNow into pYear put item 2 of tNow into pMonth put item 3 of tNow into pDate put item 4 of tNow into pHour put item 5 of tNow into pMins put item 6 of tNow into pSecs end if if pHour is empty then put 0 into pHour if pMins is empty then put 0 into pMins if pSecs is empty then put 0 into pSecs -- calculate date part of Julian number put 100 * pYear + pMonth - 190002.5 into extra put 367 * pYear into julianDate subtract trunc(7.0 * (pYear + trunc((pMonth + 9) / 12)) / 4) from julianDate add trunc(275 * pMonth / 9 ) to julianDate add pDate to julianDate -- now add the time as a fractional day add (pHour + (pMins + pSecs / 60) / 60) / 24 to julianDate add 1721013.5 to julianDate subtract .5 * extra / abs(extra) from julianDate -- compensate for the fact the UTC starts at noon add .5 to julianDate return julianDate end dateTimeToJulian -- JulianToDateTime(pJulian) -- -- JulianToDateTime(2453086.5) -- JulianToDateTime(2453087.001389) -- JulianToDateTime(2453087.003993) -- -- This function returns the date in short English date format. -- If the supplied Julian time includes a time component, -- it returns the time in either long or short 24 hour format, -- depending on whether the seconds are zero or not. -- See dateTimeToJulian for more notes about Julian dates. -- -- This function is copyright 2004 Mark Wieder and Ah, Software -- function JulianToDateTime pJulian put trunc(pJulian + .5) into jd0 if (jd0 < 2299161) then put jd0 + 1524 into c else put trunc((jd0 - 1867216.25) / 36524.25) into b put jd0 + (b - trunc(b/4)) + 1525 into c end if put trunc((c - 122.1)/365.25) into d put 365 * d + trunc(d/4) into e put trunc((c-e) / 30.6001) into f put trunc(c - e + .5) - trunc(30.6001 * f) into tDate put f - 1 - 12 * trunc(f/14) into tMonth put d - 4715 - trunc((7 + tMonth) /10) into tYear put 24 * (pJulian + .5 - jd0) into tempHour put trunc(tempHour * 60 + .5) / 60 into tHour put trunc(tHour) into tHour put (60 * (tempHour - tHour)) into tempMin put trunc(tempMin) into tMin put round(60 * (tempMin - tMin)) into tSec if tHour < 10 then put "0" before tHour if tMin < 10 then put "0" before tMin if tSec < 10 then put "0" before tSec if tHour = 0 and tMin = 0 and tSec = 0 then put tMonth & "/" & trunc(tDate) & "/" & tYear into tResult else if tSec = 0 then put tMonth & "/" & trunc(tDate) & "/" & tYear && tHour & ":" & tMin into tResult else put tMonth & "/" & trunc(tDate) & "/" & tYear && tHour & ":" & tMin & ":" & tSec into tResult end if return tResult end JulianToDateTime() -- englishToSQLdate([pDate]) -- -- englishToSQLdate() -- englishToSQLdate("6/3/09") -- -- Converts a short English date into an SQL format date (YYYY-MM-DD) -- If no date is specified, it will use the current date. -- If supplied, the date must be in English format (use the systemToEnglishDate function if necessary). -- function englishToSQLdate pDate if pDate is empty then put the short english date into pDate convert pDate from short english date to dateItems put item 2 of pDate into m if m < 10 then put "0" before m put item 3 of pDate into d if d < 10 then put "0" before d return item 1 of pDate & "-" & m & "-" & d end englishToSQLdate() -- SQLToEnglishDate([pDate], [pFourDigitYear]) -- -- SQLToEnglishDate() -- SQLToEnglishDate("2009-08-30") -- SQLToEnglishDate("2009-01-15", true) -- -- Converts an SQL format date (YYYY-MM-DD) into a short English date. -- If no date is specified, it will use the current date. -- The optional parameter pFourDigityear allows you to specify that the short date will show the year in 4 digits. -- function SQLToEnglishDate pDate, pFourDigitYear if pDate is empty then return the short english date replace "-" with comma in pDate put ",12,0,0,0" after pDate convert pDate from dateItems to short english date if pFourDigitYear = true then set the itemdel to "/" put last item of pDate into y if the number of chars in y = 4 then return pDate end if if y > 80 and y < 100 then put "19" before last item of pDate else if y < 2000 then put "20" before last item of pDate end if return pDate end SQLToEnglishDate() -- timeStamp([pSecs]) -- -- timeStamp() -- timeStamp(1249865187) -- -- Converts the time in seconds into a standard timestamp format: YYYYMMDDHHMMSS -- This is very useful to transferring times across different time zones, -- and gives a readable as well as sortable time/date indicator. -- If no time in seconds is specified, it will use the current seconds. -- function timeStamp pSecs if the length of pSecs = 14 and pSecs is a number then return pSecs -- already converted if pSecs is not empty and pSecs is not a number then return pSecs -- not valid seconds if pSecs is empty then put the seconds into tNow else put pSecs into tNow end if convert tNow to dateItems put item 1 of tNow into tStamp repeat with x = 2 to 6 put char -2 to -1 of ("00" & item x of tNow) after tStamp end repeat return tStamp end timeStamp() -- timeStampToSeconds([pStamp]) -- -- timeStampToSeconds(20090810104945) -- timeStampToSeconds(20060630140000) -- -- Converts the time in timestamp format (YYYYMMDDHHMMSS) back into time in seconds. -- If using a timeStamp, this allows you to convert it back to seconds for temporary use. -- function timeStampToSeconds pStamp if pStamp is empty then return the seconds put char 1 to 4 of pStamp & comma into tSecs put char 5 to 6 of pStamp & comma after tSecs put char 7 to 8 of pStamp & comma after tSecs put char 9 to 10 of pStamp & comma after tSecs put char 11 to 12 of pStamp & comma after tSecs put char 13 to 14 of pStamp & comma & 0 after tSecs convert tSecs from dateItems to seconds return tSecs end timeStampToSeconds() -- timeStampToShortDate([pStamp]) -- -- timeStampToShortDate(20090810104945) -- timeStampToShortDate(20060630140000) -- -- Converts the time in timestamp format (YYYYMMDDHHMMSS) to the short English date. -- This ignores the time portion of the timeStamp but is useful for display purposes. -- function timeStampToShortDate pStamp if pStamp is empty then return the short english date put char 1 to 4 of pStamp into tYear put char 5 to 6 of pStamp into tMonth put char 7 to 8 of pStamp into tDay if char 1 of tMonth = "0" then delete char 1 of tMonth if char 1 of tDay = "0" then delete char 1 of tDay put tYear & comma & tMonth & comma & tDay & ",12,0,0,0" into tDate convert tDate from dateItems to short english date return tDate end timeStampToShortDate() -- timeStampToShortTime([pStamp]) -- -- timeStampToShortTime(20090810104945) -- timeStampToShortTime(20060630140000) -- -- Converts the time in timestamp format (YYYYMMDDHHMMSS) to the shortime, -- converting from 24 to 12 hour time. -- This ignores the date portion of the timeStamp but is useful for display purposes. -- function timeStampToShortTime pStamp if pStamp is empty then return the short time put char 9 to 10 of pStamp into tHour put char 11 to 12 of pStamp into tMins if tHour > 12 then subtract 12 from tHour put "pm" into tSuffix else if tHour = 12 then put "pm" into tSuffix else put "am" into tSuffix end if -- allow for midnight if tHour = "00" then put 12 into tHour put "am" into tSuffix end if return tHour & ":" & tMins && tSuffix end timeStampToShortTime 4Date & Time Library UArialUArial ULucida Grande U Arial BlackU Arial Black UArial UArial WArial ULucida Grande @ULucida Grande WLucida Grande cGlx2General!CompilesForArchive4cExplicitVariablesfalsecIndentSwitchtruecHscrollHandlers0cSelectedChunkchar 6105 to 6530 cHtmlScript=ksF+KFD.'U9;U+R{{$bׯy(N%Wwk~MOV6++]GG''JVy}{S^Fds5Toÿ|E/IY:{{f 3벸USZ-Lg@5jn Z:kNۥ*JnkUo<_z1Tys{mUtt0@kiV*-jUZ7B^vy@\LFU-A<yvE-Ŝu0L Z#ێʗ܈sMCl¬}>pQ_YJy1*!:@FU%bz!G$njyL^XE:ɕd1542˨OhIh="QwfFvE4:@2F z92`@ꪭF#w3^-3*o$ xͳ| ;HU,?;/uYH,뙮"Z9аey_k "oɵ%("$إbLʺ\hB5 ^sͯvЖjHI31ލO,X$Vo]蒋$$iQʮ :/ U @&%ud.;Z1O[X֨iE0+dqԶ4=&ueT*/ ;r$B{fm V;'9+0]@tz гjU`Jr[ Ss6kC# fB YOވk+٘k7ykTPpd A h'Dxm)d`JUc`A DUAm׋q:Kώ->h;Z6a22-zjsʹn6++Dz[cMTsaQu]BxaoZXqE˅QFWIߑzH we2[#i`-q $Tp01Hꅡ{,fGy]roClO'j)R 0O*O-RQރ{&7YfJ/ﳬ>"z2u<(U;ż!9[M#@TGl=5LdS[eAA (T ̑0}^cV>3N;Zl)uNV<4XN2%{+~6lc .4mY3'~4ϧWBfa+ ocH[*ޔ5 ̼82CU^M6jxH߉O|FMc! l6Ec[еX@{p</dԓ.|'G.pMëa:n;^)XX%YOظkcn;M;o6;؂ P3I17Uf L ʡh?nna.&F j+d0E%vX`'惞(boRgN:{=f@Lr`@轳wFdd zGgcg7Wуǰ?i{6Ղ|pZ*@oUzڣRV(!3,a|ͼspexc#Ñ LG:f2kכU 0g;8%&룵Ej1p"_qĀM-]2do0y}}z3j c|:diK>{d T;Ns8Acc%OdK5 fXSy;{j e0|EkBx`4Z`fG{Vn)b73*;8x j? h,{$`[{ Z`աIM#v<ã>~8Q3h/"Zޮ9h0,>pV HsܒaP,3Ǧ!G}n//?:>9"'uj; S@Lj5/,CI[;\c 0ll<-kđK :a4%A|? T oZ#1"qy x=wi~j UWjBPrK־sm>DDuZ Z5U6GSD v-G1i&(ȩC|} LA\骧x]lRa`Uл: g:~}m{IC*/8lEAB=DAؓ6_`.NP躳T`o@m8JyϬoea*3z!h19pJv-j0Ə?8/N9Kl9.!8SI;W%ꛙ{u:&Ҝ,x-kSpHu:[迄kק_ܙJ[׍pt\pU F% ̖1ƺc U|}^|/տ=Hx'h3qvߒ.ɠNo[$Ma=P 5h6=҅-3kq׫rO׼vA#Ptnmen(MjG{ԦK dm [$@wq+*Ogh!IɥR:#/֋y\F:Gm?b͒]id*Wk9:I.Ģ{ͽn\(n4H4Þk>ODۨ@}C $ŏ֘j*) YLjcY"_M #ЬuSkE^/ ]oYqF,I l%rP5B怍D j\AA rM f@/RaZ2a[vi`;)NA*i }ЀJ"$\-i`%?m 7V[3R<_mM%[eM_]vر}(J ͍dz9L< <pV! 6~'EϊOq%(| TYWSxPfYtE=ʂH \=`ڦȻ<=˕.iwIKwI2u]]] "z4'zIƁH=>ß~? {O$lSshNSh  m뵻Ftۖq w+% 8l_]Y+띞4$0sbۚ{=afkjva2`qQGՔ\)~2w;rq`mQ+)V5T 8.?ϛ ͕l0Pb84T* a Yq2T0cpL$M-zHmS!-yw>3F6WH<c!c琌dr8ġI'ɗ>p,Ӊ0xM%oY ޚRn&ֵGB  E\`al> AE;pRݡ@BwxU_gIMV uĀ,ląn&_* J=xt]^#H :[1Lia' 'LQӃ?GFJgfa)rЄRܼE2V߽^KvB o-q튎)WYfCPVԛ/Ta6>dK!QwYjJ`TeQkl.=te6!0|r2ZʌM kry/ig3r[ksߗp -g%mir'ޗtdgkd#Iw9S# 4dyt~^!`7PBY}J[:Z  8ޠD}ic2tnhߡ{ sY׬稳85zhqMG| 80J!&)Cd5۩Nt?6{Ïn~TnEo,\촒]IT6L6?h9| _q$R>q2Xm!&7<.ũ:DQ2 GQ zR(enI`zF̸}%cPn&fT:/lza~PS/NG.wu,+ '֛f)L])X| Vo-a4&l1&wkx%:8Sx]N:H.d{{s3*],nAμr|j,A!/MͷGMF^7bt2.O)8tyj|`tkٖDyvNe|SÙ8Q=n!_ߌHߺ*mӍKƓBbO{xm,ArJh Xň W~Q*9Ow*iǩdF44ϡi}v6 x718s%MOw.)[f1M4N޲u i!V0Kw^<\f$,1Dߚ]DSa|vk#[Q@,5yF.mxlo 9' 0,ku CX Fݺm:(o^=8P)b1U^X2pK7wѾx!DCKjF;lRl0o=aGan-g cFontSize11cCapitalizeControlStructuresfalsecGroupVarsNConstantsfalse cConstantscHandlersListWidth170cHtmlHandlersu?O0w>U$S2U m*QP/]ӣz#iot!6{wǻ+B|:2gYY|Vb:^DcUw/>t0yT5x||kqW"j,} t_vJ@5nsXV6}ohn@%ρN񔩸6+7zc7_=&~'IzLsJ.Hg|3Kp?+NX$ u"=dQF | cFontNameVerdana cHandlersJdateOfEaster() dateTimeToJulian() dayName() dayNum() daysBetween() daysInMonth() englishToSystemDate() isLeapYear() JulianToDateTime() militaryClock() monthName() monthNum() monthNumber() numericDate() relativeDate() systemToEnglishDate() timeZone() titleCase() totalDaysInYear() twelveHourClock() weekNum() weekNumISO() yearNum()cBoldHandlersfalsecColumnarCommentsfalse cHilitedLine9cFoldingScriptsfalse cGlobals cShowLinestruecScriptChecksumcHscrollScript0cLocalscSortAlphabeticallyfalsecColorizationtrue cDirtyFlagfalseCompilesForSave3 cFolders all handlerscHandlerLinkstruecVscrollScript2646cVscrollHandlers0 cHandlerListtruecIndent cGlx2TimeStamp checksumQ-J6N 1207293785start 1207294363endstart 1169863200 cREVGeneral debugObjects breakPoints P-- internal handler for automatically constructing the handler & function list -- on buildList put the script of this stack into tList put empty into tCmds repeat for each line L in tList if word 1 of L = "on" or word 1 of L = "function" then put word 2 of L into tName get offset("(", tName) if it > 0 then delete char it to -1 of tName put tName & cr after tCmds end if end repeat delete last char of tCmds put tCmds into fld "Fn List" end buildList rctRevID 1249863832 cGlxGeneral handlers

buildList

checksumFP+'v4H code-

-- internal handler for automatically constructing the handler & function list

--

on buildList

put the script of this stack into tList

put empty into tCmds

repeat for each line L in tList

if word 1 of L = "on" or word 1 of L = "function" then

put word 2 of L into tName

get offset("(", tName)

if it > 0 then delete char it to -1 of tName

put tName & cr after tCmds

end if

end repeat

delete last char of tCmds

put tCmds into fld "Fn List"

end buildList

dirtyfalsehandler_scroll0 varCheckingfalse handler_line1scroll0 object name card id 1002 parent stackDateTimechunkchar 16286 to 16285 of field 5 immed stackDateTime cREVGeneralscriptChecksum'87#m bookmarks handlerList buildList breakPointsscriptSelection char 66 to 65 prevHandlerweekNum tempScriptscript

-- internal handler for automatically constructing the handler & function list

--

on buildList

put the script of this stack into tList

put empty into tCmds

repeat for each line L in tList

if word 1 of L = "on" or word 1 of L = "function" then

put word 2 of L into tName

get offset("(", tName)

if it > 0 then delete char it to -1 of tName

put tName & cr after tCmds

end if

end repeat

delete last char of tCmds

put tCmds into fld "Fn List"

end buildList

 Fn List)xon mouseUp put the selectedText of me into fnName put the script of this stack into tScript put lineOffset("-- " & fnName, tScript) into startLine put lineOffset("end " & fnName, tScript) into endLine put line startLine to endLine of tScript into tScript replace "-- " with "" in tScript replace "--" with "" in tScript put line 1 of tScript into tName delete line 1 to 2 of tScript put empty into tExamples put 1 into c repeat for each line L in tScript if L is empty then exit repeat put L & cr after tExamples add 1 to c end repeat delete last char of tExamples delete line 1 to c of tScript put empty into tNotes repeat for each line L in tScript if word 1 to 2 of L = "on " & fnName then exit repeat if word 1 to 2 of L = "function " & fnName then exit repeat put L & cr after tNotes end repeat replace cr & cr with "" in tNotes replace cr with space in tNotes replace "" with cr & cr in tNotes repeat while last char of tNotes = cr delete last char of tNotes end repeat put tName into fld "Name" put tExamples into fld "Examples" put tNotes into fld "Notes" end mouseUp @ 2ctRevID 1249865609 cREVGeneral scriptChecksumڛeaUy]Ik handlerListmouseUp breakPointsscriptSelectionchar 1064 to 1063 revUniqueID 1046413047887 bookmarks tempScript prevHandlermouseUpscript

on mouseUp

put the selectedText of me into fnName

put the script of this stack into tScript

put lineOffset("-- " & fnName, tScript) into startLine

put lineOffset("end " & fnName, tScript) into endLine

put line startLine to endLine of tScript into tScript

replace "-- " with "" in tScript

replace "--" with "" in tScript

put line 1 of tScript into tName

delete line 1 to 2 of tScript

put empty into tExamples

put 1 into c

repeat for each line L in tScript

if L is empty then exit repeat

put L & cr after tExamples

add 1 to c

end repeat

delete last char of tExamples

delete line 1 to c of tScript

put empty into tNotes

repeat for each line L in tScript

if word 1 to 2 of L = "on " & fnName then exit repeat

if word 1 to 2 of L = "function " & fnName then exit repeat

put L & cr after tNotes

end repeat

replace cr & cr with "¶" in tNotes

replace cr with space in tNotes

replace "¶" with cr & cr in tNotes

repeat while last char of tNotes = cr

delete last char of tNotes

end repeat

put tName into fld "Name"

put tExamples into fld "Examples"

put tNotes into fld "Notes"

end mouseUp

englishToSystemDate systemToEnglishDate isLeapYear totalDaysInYear numericDate yearNum monthName monthNum daysInMonth weekNum weekNumISO dayName dayNum daysBetween monthNumber timeZone militaryClock twelveHourClock titleCase dateOfEaster relativeDate dateTimeToJulian JulianToDateTime englishToSQLdate SQLToEnglishDate timeStamp timeStampToSeconds timeStampToShortDate timeStampToShortTime `3 Name h@=0 cREVGeneral revUniqueID 1046417012130  timeStampToShortTime([pStamp]) Notes h@0v cREVGeneral revUniqueID 1046417039292  Converts the time in timestamp format (YYYYMMDDHHMMSS) to the shortime, converting from 24 to 12 hour time. This ignores the date portion of the timeStamp but is useful for display purposes. `t  Examples5)h@l0H cREVGeneral revUniqueID 1046417048219 %timeStampToShortTime(20090810104945) %timeStampToShortTime(20060630140000)TestEon mouseUp put the selectedtext of fld "Examples" into tFn if tFn is empty then put any line of fld "Examples" into tFn put the value of tFn into tRes answer tFn & cr & tRes end mouseUp KctRevID 12498637730 cGlx2GeneralcScriptChecksumcExplicitVariablesfalsecHscrollScript0cIndentSwitchtruecLocalscSortAlphabeticallyfalsecHscrollHandlers0cSelectedChunk char 1 to 0 cHtmlScript}A0 bš7[J}@Dq"lZ}!^,˻a#`u]Qߵ0 Ggtn2a\#S"Md`;$)W'ڬ-/aj_.|ø x1@ cFontSize11cCapitalizeControlStructuresfalsecGroupVarsNConstantsfalse cConstantscHandlersListWidth116cColorizationtruecHtmlHandlersZ)I). EɶJƆƖJv6 qĜļԢb}B;.;5eKk V@jM cDirtyFlagfalse cFolders all handlerscHandlerLinkstrue cFontNameVerdana cHandlersmouseUpcVscrollScript0cBoldHandlersfalsecVscrollHandlers0cColumnarCommentsfalse cHandlerListtruecIndent cHilitedLinecFoldingScriptsfalse cGlobals cShowLinestruecGlx2TimeStamp checksumFܕ.q8Bstart 1169863200 cREVGeneral revUniqueID 1046417242008 breakPoints  New Field 1  26  cREVGeneral revUniqueID 1046818584266 Syntax:  New Field 1  `D  cREVGeneral revUniqueID 1046818584266 Examples:  New Field 1  4  cREVGeneral revUniqueID 1046818584266 Notes:  New Field 2  * cREVGeneral revUniqueID 1046819049960 Date & Time LibraryEdit stack scriptE8on mouseUp edit the script of this stack end mouseUp pKctRevID 12498637774 cREVGeneralscriptChecksumQ' q,\؛ bookmarks revUniqueID 1046417242008 handlerListmouseUpscriptSelection char 43 to 42 prevHandlermouseUp tempScriptscriptK

on mouseUp

edit the script of this stack

end mouseUp

Version  HctRevID 1249863767 cREVTable currentview Version 1.3 cREVGeneral revUniqueID 1046825007909 Version 1.3 About...Con mouseUp if not the visible of fld "Info" then set the vScroll of fld "Info" to 0 show fld "Info" else hide fld "Info" set the vScroll of fld "Info" to 0 end if end mouseUp  !ctRevID 124986376014R cGlxGeneral handlers

mouseUp

checksumz&fo"睗Y11code

on mouseUp

if not the visible of fld "Info" then

set the vscroll of fld "Info" to 0

show fld "Info"

else

hide fld "Info"

set the vscroll of fld "Info" to 0

end if

end mouseUp

dirtyfalsehandler_scroll0 varCheckingfalse handler_line1scroll0 object nameAbout... parent stackDateTimechunkchar 16286 to 16285 of field 5 immed stackDateTime cREVGeneral scriptChecksum{aKI%S{gS8 handlerListmouseUp breakPointsscriptSelectionchar 120 to 119 bookmarks revUniqueID 1046825094984 prevHandlermouseUp tempScriptscript

on mouseUp

if not the visible of fld "Info" then

set the vScroll of fld "Info" to 0

show fld "Info"

else

hide fld "Info"

set the vScroll of fld "Info" to 0

end if

end mouseUp

Infoxon mouseUp hide me end mouseUp on linkClicked pLink -- revGoURL "mailto:" & pLink revMail pLink,,"DateTime library, " & fld "Version" end linkClicked @,> cREVGeneralscriptChecksumF fB).H bookmarks revUniqueID 1046825263207 handlerListmouseUp linkClickedscriptSelectionchar 110 to 109 prevHandlermouseUp tempScriptscript

on mouseUp

hide me

end mouseUp

on linkClicked pLink

-- revGoURL "mailto:" & pLink

revMail pLink,,"DateTime library, " & fld "Version"

end linkClicked

 =This stack contains a collection of date and time utilities. All the functions are listed on the left, and clicking on any one brings up the syntax, examples and notes. Edit the stack script to see all the details. kThe "Test" button will carry out one of the listed examples, picking one randomly if none has been chosen. To use these functions, you can either copy the ones you need directly to your project, you can "start using" this stack or you can "insert the script of this stack into back (or front)". Wherever possible, these handlers are all self-sufficent and do not require any of the others to be present. The exceptions are weekNumISO() which uses dayNum() and daysInMonth() & relativeDate() which both can use monthNum() if a month name is allowed as a parameter. Warning: Revolution computes all dates starting from 1st January, 1970. This means that date calculations before that time may not be accurate. For great accuracy, convert older dates to Julian format before use.    Note: the format of this stack can be used for any script library. If the comments before the handler are laid out in the same way:  -- handler name  --  -- examples (one per line)  -- & -- notes (as many lines as you need)  --  actual handler or function 'then using the buildList handler (in the card script) will populate the list. Clicking on any item in the list, will automatically fill in the three fields on the right and allow the Test button to work without any specialised scripting. All the library routines need to be in the stack script. Feel free to use and modify these scripts in any way. Please let me know if you find them useful, if you find any bugs, or if there are more functions you would like added. cAll scripts are provided "as is" and no responsibility will be taken for any use of these scripts. #Version 1.1: updated 26 March 2003  Added numericDate() function. 4 Added better error trapping to yearNum() function. Version 1.2: updated March 2004 ( New functions thanks to ric Chatonet:  totalDaysInYear()  weekNumISO() dayNum() 7 New functions thanks to Mark Wieder and Ah, Software:  dateTimeToJulian()  JulianToDateTime()  New functions added:  titleCase()  dateOfEaster()  relativeDate() !Version 1.3: updated August 2009  New functions added by me:  englishToSQLdate  SQLToEnglishDate timeStamp  timeStampToSeconds  timeStampToShortDate  timeStampToShortTime Sarah Reichelt sarah@troz.net   `-<