libdate - Manipulating date/time information
The libdate module defines a derived type and several functions and subroutines to deal with date/time information:
Store date and time in the form of year, month, day, hour, minute
Compare dates
Basic arithmetic
Formatting date and time as a string based on a pattern
Note: Timezones and seconds are not taken into account. Also, there are no provisions to take care of the various historical introductions of the Gregorian calendar.
The module libdate defines two separate derived types, DATETYPE and JULIANDATETYPE, though this second type is mainly meant for internal use:
This type has the following fields: year, month, day, hour, minute, in that order, so that thisdate = datetype( 2007, 1, 29, 17, 0) defines a date 29 january 2007 and a time 17:00.
A duration is expressed in days, hours and minutes: period = datetype( 0, 0, 2, 1, 0) means a period of 2 days and and 1 hour. (When adding a duration to a date/time the month and year fields are ignored, as they are not additive).
Julian dates are used internally to make the computations easier. You should not need to use them explicitly, unless you want to implement new functionality.
The following functions, subroutines and operators are available:
You can compare two dates using the standard operators .EQ., .NE., .GE., .GT., .LE., .LT., with conventional meaning
Add a duration to a date. The second date/time is considered to be the duration.
The base date/time to which the duration is to be added.
The duration that will be added. Only the day, hour and minute fields are considered.
Subtract a duration from a date. The second date/time is considered to be the duration.
The base date/time from which the duration is to be subtracted.
The duration that will be subtracted. Only the day, hour and minute fields are considered.
Multiply a timestep by a real or integer factor. For the timestep, only the day, hour and minute are considered.
Factor to be applied
The duration that will be scaled.
Multiply a timestep by a real or integer factor. For the timestep, only the day, hour and minute are considered. (The order of teh arguments is reversed).
Compute the time difference between two dates. Return the value in days.
First date
Second date. If this date is earlier than the first date, the difference is positive.
Compute the number of seconds in a timestep
Timestep to be converted to seconds
Determine if the year in the date structure is a leap year or not
Date/time to be considered (only the year is of interest of course).
Compute the day of the year
Date/time to be considered.
Return the earlier of the two dates
First date/time to be considered.
Second date/time to be considered.
Return the later of the two dates
First date/time to be considered.
Second date/time to be considered.
Format a date according to a pattern.
The pattern may contain any of the following format codes:
dd - Day of month ("01" for instance)
ds - Day of month ("1" for instance, s for space)
DDD - Day of the year
HH - Hour (00-23)
HS - Hour (0-23)
mm - Month ("01" for january)
ms - Month ("1" for january, s for space)
MM - Minutes within the hour (00-59)
MS - Minutes within the hour (0-59)
YY - Year without the century
yyyy - Year with the century
Date to be converted
String containing the format pattern
String containing the result. The contents will not be longer than the pattern.
Scan a string and extract the date/time information according to the given pattern.
The pattern may contain any of the following format codes:
dd - Day of month ("01" for instance)
ds - Day of month ("1" for instance, s for space)
HH - Hour (00-23)
HS - Hour (0-23)
mm - Month ("01" for january)
ms - Month ("1" for january, s for space)
MM - Minutes within the hour (00-59)
MS - Minutes within the hour (0-59)
YY - Year without the century (two digits)
yyyy - Year with the century (one to four digits)
(space) - Skip one or more spaces in the string to be scanned
? - Skip exactly one character in the string to be scanned
(any other character) - Character in the format string and the string to be scanned must match
Date to be converted
String containing the format pattern
String containing the result. The contents will not be longer than the pattern.
Convert a date/time structure to Julian date. Mainly for internal use.
Date/time structure to be converted.
Convert a Julian date to a date/time structure. Mainly for internal use.
Julian date to be converted.
This module was written and contributed by Arjan van Dijk. Small modifications and the addition of the format_date routine by Arjen Markus.
Copyright © 2008 Arjan van Dijk <arjan dot van dijk at rivm dot nl>
Copyright © 2008 Arjen Markus <arjenmarkus at sourceforge dot net>