stdlib_datetime Module

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



Interfaces

public interface is_leap_year

  • private pure elemental function is_leap_year_int(year) result(res)

    Check if a year is a leap year.

    Arguments

    Type IntentOptional Attributes Name
    integer, intent(in) :: year

    Return Value logical

  • private pure elemental function is_leap_year_dt(dt) result(res)

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

    Arguments

    Type IntentOptional Attributes Name
    type(datetime_type), intent(in) :: dt

    Return Value logical

public interface operator(+)

  • private pure function dt_plus_td(dt, td) result(res)

    datetime + timedelta

    Arguments

    Type IntentOptional Attributes Name
    type(datetime_type), intent(in) :: dt
    type(timedelta_type), intent(in) :: td

    Return Value type(datetime_type)

  • private pure function td_plus_dt(td, dt) result(res)

    timedelta + datetime (commutative)

    Arguments

    Type IntentOptional Attributes Name
    type(timedelta_type), intent(in) :: td
    type(datetime_type), intent(in) :: dt

    Return Value type(datetime_type)

  • private pure function td_plus_td(td1, td2) result(res)

    timedelta + timedelta

    Arguments

    Type IntentOptional Attributes Name
    type(timedelta_type), intent(in) :: td1
    type(timedelta_type), intent(in) :: td2

    Return Value type(timedelta_type)

public interface operator(-)

  • private pure function dt_minus_td(dt, td) result(res)

    datetime - timedelta

    Arguments

    Type IntentOptional Attributes Name
    type(datetime_type), intent(in) :: dt
    type(timedelta_type), intent(in) :: td

    Return Value type(datetime_type)

  • private pure function dt_minus_dt(dt1, dt2) result(res)

    datetime - datetime (both converted to UTC)

    Arguments

    Type IntentOptional Attributes Name
    type(datetime_type), intent(in) :: dt1
    type(datetime_type), intent(in) :: dt2

    Return Value type(timedelta_type)

  • private pure function td_minus_td(td1, td2) result(res)

    timedelta - timedelta

    Arguments

    Type IntentOptional Attributes Name
    type(timedelta_type), intent(in) :: td1
    type(timedelta_type), intent(in) :: td2

    Return Value type(timedelta_type)

  • private pure function td_negate(td) result(res)

    Unary minus: -timedelta

    Arguments

    Type IntentOptional Attributes Name
    type(timedelta_type), intent(in) :: td

    Return Value type(timedelta_type)

public interface operator(/=)

  • private pure function dt_ne(dt1, dt2) result(res)

    Arguments

    Type IntentOptional Attributes Name
    type(datetime_type), intent(in) :: dt1
    type(datetime_type), intent(in) :: dt2

    Return Value logical

  • private pure function td_ne(td1, td2) result(res)

    Arguments

    Type IntentOptional Attributes Name
    type(timedelta_type), intent(in) :: td1
    type(timedelta_type), intent(in) :: td2

    Return Value logical

public interface operator(<)

  • private pure function dt_lt(dt1, dt2) result(res)

    Arguments

    Type IntentOptional Attributes Name
    type(datetime_type), intent(in) :: dt1
    type(datetime_type), intent(in) :: dt2

    Return Value logical

  • private pure function td_lt(td1, td2) result(res)

    Arguments

    Type IntentOptional Attributes Name
    type(timedelta_type), intent(in) :: td1
    type(timedelta_type), intent(in) :: td2

    Return Value logical

public interface operator(<=)

  • private pure function dt_le(dt1, dt2) result(res)

    Arguments

    Type IntentOptional Attributes Name
    type(datetime_type), intent(in) :: dt1
    type(datetime_type), intent(in) :: dt2

    Return Value logical

  • private pure function td_le(td1, td2) result(res)

    Arguments

    Type IntentOptional Attributes Name
    type(timedelta_type), intent(in) :: td1
    type(timedelta_type), intent(in) :: td2

    Return Value logical

public interface operator(==)

  • private pure function dt_eq(dt1, dt2) result(res)

    Arguments

    Type IntentOptional Attributes Name
    type(datetime_type), intent(in) :: dt1
    type(datetime_type), intent(in) :: dt2

    Return Value logical

  • private pure function td_eq(td1, td2) result(res)

    Arguments

    Type IntentOptional Attributes Name
    type(timedelta_type), intent(in) :: td1
    type(timedelta_type), intent(in) :: td2

    Return Value logical

public interface operator(>)

  • private pure function dt_gt(dt1, dt2) result(res)

    Arguments

    Type IntentOptional Attributes Name
    type(datetime_type), intent(in) :: dt1
    type(datetime_type), intent(in) :: dt2

    Return Value logical

  • private pure function td_gt(td1, td2) result(res)

    Arguments

    Type IntentOptional Attributes Name
    type(timedelta_type), intent(in) :: td1
    type(timedelta_type), intent(in) :: td2

    Return Value logical

public interface operator(>=)

  • private pure function dt_ge(dt1, dt2) result(res)

    Arguments

    Type IntentOptional Attributes Name
    type(datetime_type), intent(in) :: dt1
    type(datetime_type), intent(in) :: dt2

    Return Value logical

  • private pure function td_ge(td1, td2) result(res)

    Arguments

    Type IntentOptional Attributes Name
    type(timedelta_type), intent(in) :: td1
    type(timedelta_type), intent(in) :: td2

    Return Value logical


Derived Types

type, public ::  datetime_type

Represents a specific point in time.

Components

Type Visibility Attributes Name Initial
integer, public :: day = 1

Day (1-31)

integer, public :: hour = 0

Hour (0-23)

integer, public :: millisecond = 0

Millisecond (0-999)

integer, public :: minute = 0

Minute (0-59)

integer, public :: month = 1

Month (1-12)

integer, public :: second = 0

Second (0-59)

integer, public :: utc_offset_minutes = 0

UTC offset in minutes

integer, public :: year = 1

Year (1-9999)

type, public ::  timedelta_type

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

Components

Type Visibility Attributes Name Initial
integer, public :: days = 0

Number of days

integer, public :: milliseconds = 0

Milliseconds (0-999)

integer, public :: seconds = 0

Seconds (0-86399)


Functions

public pure function datetime(year, month, day, hour, minute, second, millisecond, utc_offset_minutes) result(dt)

License
Creative Commons License
Version
experimental

Create a datetime_type from individual components.

Arguments

Type IntentOptional Attributes Name
integer, intent(in), optional :: year
integer, intent(in), optional :: month
integer, intent(in), optional :: day
integer, intent(in), optional :: hour
integer, intent(in), optional :: minute
integer, intent(in), optional :: second
integer, intent(in), optional :: millisecond
integer, intent(in), optional :: utc_offset_minutes

Return Value type(datetime_type)

public pure function day_of_week(dt) result(dow)

License
Creative Commons License
Version
experimental

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

Arguments

Type IntentOptional Attributes Name
type(datetime_type), intent(in) :: dt

Return Value integer

public pure function day_of_year(dt) result(doy)

License
Creative Commons License
Version
experimental

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

Arguments

Type IntentOptional Attributes Name
type(datetime_type), intent(in) :: dt

Return Value integer

public pure function days_in_month(month, year) result(d)

License
Creative Commons License
Version
experimental

Return the number of days in a given month.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: month
integer, intent(in) :: year

Return Value integer

public pure function days_in_year(year) result(d)

License
Creative Commons License
Version
experimental

Return 366 for leap years, 365 otherwise.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: year

Return Value integer

public pure function epoch() result(dt)

License
Creative Commons License
Version
experimental

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

Arguments

None

Return Value type(datetime_type)

public pure function format_datetime(dt) result(str)

License
Creative Commons License
Version
experimental

Format a datetime_type as an ISO 8601 string.

Arguments

Type IntentOptional Attributes Name
type(datetime_type), intent(in) :: dt

Return Value character(len=:), allocatable

public pure function format_timedelta(td) result(str)

License
Creative Commons License
Version
experimental

Format a timedelta_type as a readable string.

Arguments

Type IntentOptional Attributes Name
type(timedelta_type), intent(in) :: td

Return Value character(len=:), allocatable

public function now() result(dt)

License
Creative Commons License
Version
experimental

Return the current local date and time.

Arguments

None

Return Value type(datetime_type)

public function now_utc() result(dt)

License
Creative Commons License
Version
experimental

Return the current UTC date and time.

Arguments

None

Return Value type(datetime_type)

public function parse_datetime(str, stat) result(dt)

License
Creative Commons License
Version
experimental

Parse an ISO 8601 date/time string.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
integer, intent(out), optional :: stat

Return Value type(datetime_type)

public pure function timedelta(days, hours, minutes, seconds, milliseconds) result(td)

License
Creative Commons License
Version
experimental

Create a normalized timedelta_type from mixed units.

Arguments

Type IntentOptional Attributes Name
integer, intent(in), optional :: days
integer, intent(in), optional :: hours
integer, intent(in), optional :: minutes
integer, intent(in), optional :: seconds
integer, intent(in), optional :: milliseconds

Return Value type(timedelta_type)

public pure function to_utc(dt) result(utc_dt)

License
Creative Commons License
Version
experimental

Convert a datetime to UTC.

Arguments

Type IntentOptional Attributes Name
type(datetime_type), intent(in) :: dt

Return Value type(datetime_type)

public pure function total_seconds(td) result(secs)

License
Creative Commons License
Version
experimental

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

Arguments

Type IntentOptional Attributes Name
type(timedelta_type), intent(in) :: td

Return Value real(kind=dp)