stdlib_datetime#

See also the specification page: stdlib_datetime.

stdlib_datetime (module)#

Date, time, and time interval handling for Fortran. (Specification: stdlib_datetime)

Types

datetime_type (type)#

datetime_type (type)

Represents a specific point in time.

Attributes:
yearinteger, Default = 1

Year (1-9999)

monthinteger, Default = 1

Month (1-12)

dayinteger, Default = 1

Day (1-31)

hourinteger, Default = 0

Hour (0-23)

minuteinteger, Default = 0

Minute (0-59)

secondinteger, Default = 0

Second (0-59)

millisecondinteger, Default = 0

Millisecond (0-999)

utc_offset_minutesinteger, Default = 0

UTC offset in minutes

timedelta_type (type)#

timedelta_type (type)

Represents a duration or time interval. Normalized: seconds in [0,86399], ms in [0,999]. Days can be negative for negative durations.

Attributes:
daysinteger, Default = 0

Number of days

secondsinteger, Default = 0

Seconds (0-86399)

millisecondsinteger, Default = 0

Milliseconds (0-999)

Interfaces

operator(+) (interface)#

operator(+) (interface)
Procedures:

operator(-) (interface)#

operator(-) (interface)
Procedures:

operator(==) (interface)#

operator(==) (interface)
Procedures:

operator(/=) (interface)#

operator(/=) (interface)
Procedures:

operator(<) (interface)#

operator(<) (interface)
Procedures:

operator(<=) (interface)#

operator(<=) (interface)
Procedures:

operator(>) (interface)#

operator(>) (interface)
Procedures:

operator(>=) (interface)#

operator(>=) (interface)
Procedures:

is_leap_year (interface)#

is_leap_year (interface)
Procedures:

Procedures

datetime (function)#

pure function datetime(year, month, day, hour, minute, second, millisecond, utc_offset_minutes) -> dt

Create a datetime_type from individual components.

Arguments:
yearinteger, intent(in), optional
monthinteger, intent(in), optional
dayinteger, intent(in), optional
hourinteger, intent(in), optional
minuteinteger, intent(in), optional
secondinteger, intent(in), optional
millisecondinteger, intent(in), optional
utc_offset_minutesinteger, intent(in), optional
Returns:
dttype(datetime_type)

timedelta (function)#

pure function timedelta(days, hours, minutes, seconds, milliseconds) -> td

Create a normalized timedelta_type from mixed units.

Arguments:
daysinteger, intent(in), optional
hoursinteger, intent(in), optional
minutesinteger, intent(in), optional
secondsinteger, intent(in), optional
millisecondsinteger, intent(in), optional
Returns:
tdtype(timedelta_type)

now (function)#

function now -> dt

Return the current local date and time.

Returns:
dttype(datetime_type)

now_utc (function)#

function now_utc -> dt

Return the current UTC date and time.

Returns:
dttype(datetime_type)

epoch (function)#

pure function epoch -> dt

Return the Unix epoch: 1970-01-01T00:00:00Z.

Returns:
dttype(datetime_type)

dt_plus_td (function)#

pure function dt_plus_td(dt, td) -> res

datetime + timedelta

Arguments:
dttype(datetime_type), intent(in)
tdtype(timedelta_type), intent(in)
Returns:
restype(datetime_type)

td_plus_dt (function)#

pure function td_plus_dt(td, dt) -> res

timedelta + datetime (commutative)

Arguments:
tdtype(timedelta_type), intent(in)
dttype(datetime_type), intent(in)
Returns:
restype(datetime_type)

td_plus_td (function)#

pure function td_plus_td(td1, td2) -> res

timedelta + timedelta

Arguments:
td1type(timedelta_type), intent(in)
td2type(timedelta_type), intent(in)
Returns:
restype(timedelta_type)

dt_minus_td (function)#

pure function dt_minus_td(dt, td) -> res

datetime - timedelta

Arguments:
dttype(datetime_type), intent(in)
tdtype(timedelta_type), intent(in)
Returns:
restype(datetime_type)

dt_minus_dt (function)#

pure function dt_minus_dt(dt1, dt2) -> res

datetime - datetime (both converted to UTC)

Arguments:
dt1type(datetime_type), intent(in)
dt2type(datetime_type), intent(in)
Returns:
restype(timedelta_type)

td_minus_td (function)#

pure function td_minus_td(td1, td2) -> res

timedelta - timedelta

Arguments:
td1type(timedelta_type), intent(in)
td2type(timedelta_type), intent(in)
Returns:
restype(timedelta_type)

td_negate (function)#

pure function td_negate(td) -> res

Unary minus: -timedelta

Arguments:
tdtype(timedelta_type), intent(in)
Returns:
restype(timedelta_type)

dt_eq (function)#

pure function dt_eq(dt1, dt2) -> res
Arguments:
dt1type(datetime_type), intent(in)
dt2type(datetime_type), intent(in)
Returns:
reslogical

dt_ne (function)#

pure function dt_ne(dt1, dt2) -> res
Arguments:
dt1type(datetime_type), intent(in)
dt2type(datetime_type), intent(in)
Returns:
reslogical

dt_lt (function)#

pure function dt_lt(dt1, dt2) -> res
Arguments:
dt1type(datetime_type), intent(in)
dt2type(datetime_type), intent(in)
Returns:
reslogical

dt_le (function)#

pure function dt_le(dt1, dt2) -> res
Arguments:
dt1type(datetime_type), intent(in)
dt2type(datetime_type), intent(in)
Returns:
reslogical

dt_gt (function)#

pure function dt_gt(dt1, dt2) -> res
Arguments:
dt1type(datetime_type), intent(in)
dt2type(datetime_type), intent(in)
Returns:
reslogical

dt_ge (function)#

pure function dt_ge(dt1, dt2) -> res
Arguments:
dt1type(datetime_type), intent(in)
dt2type(datetime_type), intent(in)
Returns:
reslogical

td_eq (function)#

pure function td_eq(td1, td2) -> res
Arguments:
td1type(timedelta_type), intent(in)
td2type(timedelta_type), intent(in)
Returns:
reslogical

td_ne (function)#

pure function td_ne(td1, td2) -> res
Arguments:
td1type(timedelta_type), intent(in)
td2type(timedelta_type), intent(in)
Returns:
reslogical

td_lt (function)#

pure function td_lt(td1, td2) -> res
Arguments:
td1type(timedelta_type), intent(in)
td2type(timedelta_type), intent(in)
Returns:
reslogical

td_le (function)#

pure function td_le(td1, td2) -> res
Arguments:
td1type(timedelta_type), intent(in)
td2type(timedelta_type), intent(in)
Returns:
reslogical

td_gt (function)#

pure function td_gt(td1, td2) -> res
Arguments:
td1type(timedelta_type), intent(in)
td2type(timedelta_type), intent(in)
Returns:
reslogical

td_ge (function)#

pure function td_ge(td1, td2) -> res
Arguments:
td1type(timedelta_type), intent(in)
td2type(timedelta_type), intent(in)
Returns:
reslogical

format_datetime (function)#

pure function format_datetime(dt) -> str

Format a datetime_type as an ISO 8601 string.

Arguments:
dttype(datetime_type), intent(in)
Returns:
strcharacter(len=:), allocatable

format_timedelta (function)#

pure function format_timedelta(td, compact) -> str

Format a timedelta_type as a readable string. When days == 0 and compact is present and .true., sub-second/sub-minute durations are formatted compactly (e.g. “5ms”, “1.500s”, “05:30[.mmm]”); the “0 days, “ prefix is omitted. When compact is absent or .false., or when days /= 0, the original verbose format is preserved.

Arguments:
tdtype(timedelta_type), intent(in)
compactlogical, intent(in), optional
Returns:
strcharacter(len=:), allocatable

parse_datetime (function)#

function parse_datetime(str, stat) -> dt

Parse an ISO 8601 date/time string.

Arguments:
strcharacter(len=*), intent(in)
statinteger, intent(out), optional
Returns:
dttype(datetime_type)

is_leap_year_int (function)#

pure elemental function is_leap_year_int(year) -> res

Check if a year is a leap year.

Arguments:
yearinteger, intent(in)
Returns:
reslogical

is_leap_year_dt (function)#

pure elemental function is_leap_year_dt(dt) -> res

Check if a datetime’s year is a leap year.

Arguments:
dttype(datetime_type), intent(in)
Returns:
reslogical

days_in_month (function)#

pure function days_in_month(month, year) -> d

Return the number of days in a given month.

Arguments:
monthinteger, intent(in)
yearinteger, intent(in)
Returns:
dinteger

days_in_year (function)#

pure function days_in_year(year) -> d

Return 366 for leap years, 365 otherwise.

Arguments:
yearinteger, intent(in)
Returns:
dinteger

day_of_year (function)#

pure function day_of_year(dt) -> doy

Return the ordinal day of the year (1-366).

Arguments:
dttype(datetime_type), intent(in)
Returns:
doyinteger

day_of_week (function)#

pure function day_of_week(dt) -> dow

Return ISO weekday (1=Monday … 7=Sunday).

Arguments:
dttype(datetime_type), intent(in)
Returns:
dowinteger

to_utc (function)#

pure function to_utc(dt) -> utc_dt

Convert a datetime to UTC.

Arguments:
dttype(datetime_type), intent(in)
Returns:
utc_dttype(datetime_type)

total_seconds (function)#

pure function total_seconds(td) -> secs

Return the total duration in seconds as real(dp).

Arguments:
tdtype(timedelta_type), intent(in)
Returns:
secsreal(kind=dp)