-- Date Calculations
--
-- Sep 1, 1996
-- written by Junko C. Miura, Rapid Deployment Software
-- Contributed to the Public Domain
--
-- Aug 5, 2010
-- converted by Jean-Marc Duro to a reusable unit
-- Date Calculations
--
-- Sep 1, 1996
-- written by Junko C. Miura, Rapid Deployment Software
-- Contributed to the Public Domain
--
-- Aug 5, 2010
-- converted by Jean-Marc Duro to a reusable unit
Following global constants are defined:
Language used to format date strings
Names of the days in a week (english)
Names of the days in a week (french)
Names of the monthes in a year (english)
Names of the monthes in a year (french)
Following global functions are defined:
year on 4 digits
month
day
lunar_landing = get_factor(1969, 7, 20)
gets the day of the week of a specified date
Params:year on 4 digits
month
day
printf(1, "The lunar module Eagle landed on the moon on %s July 20, 1969\n",
{WEEK[day_of_week(1969, 7, 20)]})
printf(1, "Le module lunaire Eagle a atterri sur la lune le %s 20 juillet 1969\n",
{SEMAINE[day_of_week(1969, 7, 20)]})
gets the number of days between two dates
Params:printf(1, "The lunar module Eagle landed on the moon %d days ago\n", days_between_dates({1969, 7, 20}, {1900+dt[1], dt[2], dt[3]}))
returns date and time in ISO format
Params:date in datetime format
output format:
* STRING_DATE: "YYYY-MM-DD HH:MM:SS"
* FILE_DATE : "YYYY-MM-DD_HH-MM-SS"
sequence: date and time in ISO format
puts(1, datetime_to_iso(date(), STRING_DATE) & " -> message\n")
2016-11-14 08:14:14 -> message
puts(1, datetime_to_iso(date(), FILE_DATE) & ".log")
2016-11-14_08-14-14.log
prefixes the given message by date and time for logging purposes
Params:string to prefix
sequence: given string prefixed by date and time
converts a string in datetime format
Params:date and time in string format
monthes names have to be complete: no abbreviation
monthes decoding according to DATE_LANGUAGE constant: "en" or "fr"
seconds are optional
sequence: datetime
puts(1, "string_to_datetime(\"27 octobre 1996 11:10:00\") = " &
object_dump(string_to_datetime("27 octobre 1996 11:10:00")) & "\n")
string_to_datetime("27 octobre 1996 11:10:00") = {1996,10,27,11,10,0}
puts(1, "string_to_datetime(\"27 octobre 1996 11:10\") = " &
object_dump(string_to_datetime("27 octobre 1996 11:10")) & "\n")
string_to_datetime("27 octobre 1996 11:10") = {1996,10,27,11,10,0}
converts a number of seconds in a string formatted with days, hours,
minutes and seconds
number of seconds to convert
day abbreviation according to DATE_LANGUAGE constant
string
puts(1, "seconds_to_time_string(99999) = " &
object_dump(seconds_to_time_string(99999)) & "\n")
seconds_to_time_string(99999) = '01j 03h 46mn 39s'
converts an Excel datetime atom in a datetime sequence
Params:Excel datetime atom to convert
sequence: datetime
birth = datetime_to_excel_time({1996, 10, 27, 11, 10, 0})
printf(1, "excel_time_to_datetime(%f) = %s\n", {birth,
object_dump(excel_time_to_datetime(birth))})
excel_time_to_datetime(35365.465278) = {1996,10,27,11,10,0}
converts a datetime sequence in an Excel datetime atom
Params:datetime sequence to convert
Excel datetime atom
birth = datetime_to_excel_time({1996, 10, 27, 11, 10, 0})
printf(1, "datetime_to_excel_time(%s) = %f\n", {
object_dump({1996, 10, 27, 11, 10, 0}), birth})
datetime_to_excel_time({1996,10,27,11,10,0}) = 35365.465278