dm_time Module

Date and time functions.

ISO 8601/RFC 3339 is used as the universal date and time format. Date and time are separated by character T. The time has microsecond resolution, a time zone is mandatory. A valid timestamp must contain at least the full year, and be between 4 and 32 characters long. For example, the string 1970-01-01T00:00:00.000000+00:00 is a valid DMPACK time stamp.


Uses

  • module~~dm_time~~UsesGraph module~dm_time dm_time module~dm_error dm_error module~dm_time->module~dm_error module~dm_kind dm_kind module~dm_time->module~dm_kind module~dm_util dm_util module~dm_time->module~dm_util module~dm_error->module~dm_kind module~dm_ascii dm_ascii module~dm_error->module~dm_ascii iso_fortran_env iso_fortran_env module~dm_kind->iso_fortran_env module~dm_util->module~dm_error module~dm_util->module~dm_kind

Used by

  • module~~dm_time~~UsedByGraph module~dm_time dm_time module~dm_api dm_api module~dm_api->module~dm_time module~dm_atom dm_atom module~dm_atom->module~dm_time module~dm_log dm_log module~dm_atom->module~dm_log module~dm_beat dm_beat module~dm_beat->module~dm_time module~dm_cgi dm_cgi module~dm_cgi->module~dm_time module~dm_db dm_db module~dm_db->module~dm_time module~dm_dp dm_dp module~dm_dp->module~dm_time module~dm_log->module~dm_time module~dm_observ dm_observ module~dm_log->module~dm_observ module~dm_mail dm_mail module~dm_mail->module~dm_time module~dm_observ->module~dm_time module~dm_request dm_request module~dm_observ->module~dm_request module~dm_plot dm_plot module~dm_plot->module~dm_time module~dm_plot->module~dm_dp module~dm_report dm_report module~dm_report->module~dm_time module~dm_report->module~dm_log module~dm_report->module~dm_plot module~dm_request->module~dm_time module~dm_sync dm_sync module~dm_sync->module~dm_time module~dm_sync->module~dm_observ module~dm_test dm_test module~dm_test->module~dm_time module~dmpack dmpack module~dmpack->module~dm_time module~dmpack->module~dm_api module~dmpack->module~dm_atom module~dmpack->module~dm_beat module~dmpack->module~dm_cgi module~dmpack->module~dm_db module~dmpack->module~dm_dp module~dmpack->module~dm_log module~dmpack->module~dm_mail module~dmpack->module~dm_observ module~dmpack->module~dm_plot module~dmpack->module~dm_report module~dmpack->module~dm_request module~dmpack->module~dm_sync module~dmpack->module~dm_test module~dm_block dm_block module~dmpack->module~dm_block module~dm_cgi_router dm_cgi_router module~dmpack->module~dm_cgi_router module~dm_fcgi dm_fcgi module~dmpack->module~dm_fcgi module~dm_geocom dm_geocom module~dmpack->module~dm_geocom module~dm_geocom_api dm_geocom_api module~dmpack->module~dm_geocom_api module~dm_job dm_job module~dmpack->module~dm_job module~dm_json dm_json module~dmpack->module~dm_json module~dm_logger dm_logger module~dmpack->module~dm_logger module~dm_lua_geocom dm_lua_geocom module~dmpack->module~dm_lua_geocom module~dm_mqueue dm_mqueue module~dmpack->module~dm_mqueue module~dm_geojson dm_geojson module~dmpack->module~dm_geojson module~dm_jsonl dm_jsonl module~dmpack->module~dm_jsonl module~dm_mqueue_util dm_mqueue_util module~dmpack->module~dm_mqueue_util proc~dm_arg_validate dm_arg_validate proc~dm_arg_validate->module~dm_time proc~dm_arg_validate->module~dm_log proc~dm_html_beat dm_html_beat proc~dm_html_beat->module~dm_time proc~dm_html_beat->module~dm_beat proc~dm_html_beats dm_html_beats proc~dm_html_beats->module~dm_time proc~dm_html_beats->module~dm_beat proc~dm_html_time dm_html_time proc~dm_html_time->module~dm_time proc~dm_test_run dm_test_run proc~dm_test_run->module~dm_time module~dm_block->module~dm_dp module~dm_cgi_router->module~dm_cgi module~dm_fcgi->module~dm_cgi module~dm_geocom->module~dm_request module~dm_geocom->module~dm_geocom_api module~dm_geocom_api->module~dm_request module~dm_job->module~dm_observ module~dm_json->module~dm_dp module~dm_logger->module~dm_log module~dm_logger->module~dm_observ module~dm_lua_geocom->module~dm_request module~dm_lua_geocom->module~dm_geocom_api module~dm_mqueue->module~dm_log module~dm_mqueue->module~dm_observ proc~dm_csv_header_observ dm_csv_header_observ proc~dm_csv_header_observ->module~dm_observ proc~dm_csv_header_observ->module~dm_request proc~dm_db_insert_beat dm_db_insert_beat proc~dm_db_insert_beat->module~dm_beat proc~dm_db_insert_beats dm_db_insert_beats proc~dm_db_insert_beats->module~dm_beat proc~dm_db_insert_log dm_db_insert_log proc~dm_db_insert_log->module~dm_log proc~dm_db_insert_observ dm_db_insert_observ proc~dm_db_insert_observ->module~dm_observ proc~dm_db_insert_observs dm_db_insert_observs proc~dm_db_insert_observs->module~dm_observ proc~dm_db_insert_sync dm_db_insert_sync proc~dm_db_insert_sync->module~dm_sync proc~dm_db_insert_sync_log dm_db_insert_sync_log proc~dm_db_insert_sync_log->module~dm_sync proc~dm_db_insert_sync_node dm_db_insert_sync_node proc~dm_db_insert_sync_node->module~dm_sync proc~dm_db_insert_sync_observ dm_db_insert_sync_observ proc~dm_db_insert_sync_observ->module~dm_sync proc~dm_db_insert_sync_sensor dm_db_insert_sync_sensor proc~dm_db_insert_sync_sensor->module~dm_sync proc~dm_db_insert_sync_target dm_db_insert_sync_target proc~dm_db_insert_sync_target->module~dm_sync proc~dm_db_select_beat dm_db_select_beat proc~dm_db_select_beat->module~dm_beat proc~dm_db_select_log dm_db_select_log proc~dm_db_select_log->module~dm_log proc~dm_db_select_logs_by_observ dm_db_select_logs_by_observ proc~dm_db_select_logs_by_observ->module~dm_log proc~dm_db_select_observ dm_db_select_observ proc~dm_db_select_observ->module~dm_observ proc~dm_db_select_observ_ids dm_db_select_observ_ids proc~dm_db_select_observ_ids->module~dm_observ proc~dm_db_select_observ_views dm_db_select_observ_views proc~dm_db_select_observ_views->module~dm_observ proc~dm_db_select_observs_by_id dm_db_select_observs_by_id proc~dm_db_select_observs_by_id->module~dm_observ proc~dm_db_select_observs_by_time dm_db_select_observs_by_time proc~dm_db_select_observs_by_time->module~dm_observ proc~dm_db_select_sync_log dm_db_select_sync_log proc~dm_db_select_sync_log->module~dm_sync proc~dm_db_select_sync_logs dm_db_select_sync_logs proc~dm_db_select_sync_logs->module~dm_sync proc~dm_db_select_sync_node dm_db_select_sync_node proc~dm_db_select_sync_node->module~dm_sync proc~dm_db_select_sync_nodes dm_db_select_sync_nodes proc~dm_db_select_sync_nodes->module~dm_sync proc~dm_db_select_sync_observ dm_db_select_sync_observ proc~dm_db_select_sync_observ->module~dm_sync proc~dm_db_select_sync_observs dm_db_select_sync_observs proc~dm_db_select_sync_observs->module~dm_sync proc~dm_db_select_sync_sensor dm_db_select_sync_sensor proc~dm_db_select_sync_sensor->module~dm_sync proc~dm_db_select_sync_sensors dm_db_select_sync_sensors proc~dm_db_select_sync_sensors->module~dm_sync proc~dm_db_select_sync_target dm_db_select_sync_target proc~dm_db_select_sync_target->module~dm_sync proc~dm_db_select_sync_targets dm_db_select_sync_targets proc~dm_db_select_sync_targets->module~dm_sync proc~dm_html_cgi_env dm_html_cgi_env proc~dm_html_cgi_env->module~dm_cgi proc~dm_html_log dm_html_log proc~dm_html_log->module~dm_log proc~dm_html_logs dm_html_logs proc~dm_html_logs->module~dm_log proc~dm_html_observ dm_html_observ proc~dm_html_observ->module~dm_observ proc~dm_html_observs dm_html_observs proc~dm_html_observs->module~dm_observ proc~dm_html_request dm_html_request proc~dm_html_request->module~dm_request proc~dm_lua_api_register dm_lua_api_register proc~dm_lua_api_register->module~dm_log proc~dm_regex_request dm_regex_request proc~dm_regex_request->module~dm_request proc~dm_regex_response_string dm_regex_response_string proc~dm_regex_response_string->module~dm_request proc~dm_test_dummy_beat dm_test_dummy_beat proc~dm_test_dummy_beat->module~dm_beat proc~dm_test_dummy_log dm_test_dummy_log proc~dm_test_dummy_log->module~dm_log proc~dm_test_dummy_observ dm_test_dummy_observ proc~dm_test_dummy_observ->module~dm_observ proc~dm_test_dummy_observ->module~dm_request proc~dm_test_dummy_request dm_test_dummy_request proc~dm_test_dummy_request->module~dm_request proc~dm_tty_read_request dm_tty_read_request proc~dm_tty_read_request->module~dm_request proc~dm_tty_write_request dm_tty_write_request proc~dm_tty_write_request->module~dm_request proc~dm_z_compress_type dm_z_compress_type proc~dm_z_compress_type->module~dm_beat proc~dm_z_compress_type->module~dm_log proc~dm_z_compress_type->module~dm_observ module~dm_geojson->module~dm_json module~dm_jsonl->module~dm_json module~dm_mqueue_util->module~dm_mqueue proc~dm_config_open dm_config_open proc~dm_config_open->module~dm_lua_geocom proc~luaopen_libdmpack luaopen_libdmpack proc~luaopen_libdmpack->module~dm_lua_geocom

Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: TIME_LEN = 32

Length of ISO 8601 time stamp.

integer, public, parameter :: TIME_HUMAN_LEN = 26

Length of human-readable time stamp.

character(len=*), public, parameter :: TIME_DEFAULT = '1970-01-01T00:00:00.000000+00:00'

Default ISO 8601 time stamp with microseconds.


Interfaces

public interface dm_time_from_unix

Converts Unix epoch to integer or string representation.

  • private impure elemental function time_from_unix_integer(epoch, year, month, day, hour, minute, second) result(rc)

    Converts the 8-byte calendar time epoch in UTC to broken-down time representation. The argument epoch is the number of seconds elapsed since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). The function calls gmtime_r() internally (SUSv2).

    Returns E_SYSTEM if the system call failed.

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=i8), intent(in) :: epoch

    Unix time stamp in seconds (UTC).

    integer, intent(out), optional :: year

    Year part of time stamp.

    integer, intent(out), optional :: month

    Month part of time stamp.

    integer, intent(out), optional :: day

    Day of month part of time stamp.

    integer, intent(out), optional :: hour

    Hour part of time stamp.

    integer, intent(out), optional :: minute

    Minute part of time stamp.

    integer, intent(out), optional :: second

    Second part of time stamp.

    Return Value integer

  • private impure elemental function time_from_unix_string(epoch, time) result(rc)

    Converts the 8-byte calendar time epoch in UTC to ISO 8601 representation. The argument epoch is the number of seconds elapsed since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). The function calls gmtime_r() internally (SUSv2).

    Returns E_SYSTEM if the system call failed.

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=i8), intent(in) :: epoch

    Unix time stamp in seconds (UTC).

    character(len=TIME_LEN), intent(out) :: time

    ISO 8601 representation.

    Return Value integer


Derived Types

type, public ::  time_delta_type

Time delta type to store elapsed time.

Components

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

Bygone days.

integer, public :: hours = 0

Bygone hours.

integer, public :: minutes = 0

Bygone minutes.

integer, public :: seconds = 0

Bygone seconds.


Functions

public pure elemental function dm_time_create(year, month, day, hour, minute, second, usecond, zone) result(str)

Returns 32-characters long time stamp string in ISO 8601/RFC 3339 of the form 1970-01-01T00:00:00.000000+00:00. Optional argument zone sets the time zone and has to be of the form [+|-]hh:mm, for example, +00:00 or -01:00.

Arguments

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

Year (YYYY).

integer, intent(in), optional :: month

Month (MM).

integer, intent(in), optional :: day

Day of month (DD).

integer, intent(in), optional :: hour

Hour (hh).

integer, intent(in), optional :: minute

Minute (mm).

integer, intent(in), optional :: second

Second (ss).

integer, intent(in), optional :: usecond

Microsecond (ffffff).

character(len=6), intent(in), optional :: zone

Timezone ([+|-]hh:mm).

Return Value character(len=time_len)

public function dm_time_delta_to_string(time_delta, days, hours, minutes, seconds) result(str)

Converts time_delta_type to string of format [d days ][h hours ][m mins ][s secs].

Arguments

Type IntentOptional Attributes Name
type(time_delta_type), intent(inout) :: time_delta

Time delta type.

logical, intent(in), optional :: days

Write days, .true. by default.

logical, intent(in), optional :: hours

Write hours, .true. by default.

logical, intent(in), optional :: minutes

Write minutes, .true. by default.

logical, intent(in), optional :: seconds

Write seconds, .true. by default.

Return Value character(len=:), allocatable

public impure elemental function dm_time_diff(time1, time2, seconds) result(rc)

Returns the time difference between time1 and time2 as 8-byte integer seconds [sec]. The function does not validate the time stamps. Make sure to only pass valid values. On error, the result seconds is huge(0_i8).

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=TIME_LEN), intent(in) :: time1

ISO 8601 time stamp.

character(len=TIME_LEN), intent(in) :: time2

ISO 8601 time stamp.

integer(kind=i8), intent(out) :: seconds

Time delta [sec].

Return Value integer

public function dm_time_mseconds() result(mseconds)

Returns current time in mseconds as 8-byte integer (Unix Epoch). On error, the result is 0.

Arguments

None

Return Value integer(kind=i8)

public impure elemental function dm_time_now() result(str)

Returns current date and time as 32-characters long string in ISO 8601/RFC 3339 format (1970-01-01T00:00:00.000000+00:00), and microsecond resolution.

Arguments

None

Return Value character(len=time_len)

public impure elemental function dm_time_rfc2822() result(str)

Returns current date and time as 31-characters long string in RFC 2822 format.

Arguments

None

Return Value character(len=31)

public pure elemental function dm_time_strip_useconds(time) result(str)

Strips the microseconds part of the given ISO 8601 time stamp and returns a 25-characters long string. The function does not validate the time stamp for performance reasons. Make sure that only a valid 32-characters long ISO 8601 time stamp is passed in time.

Arguments

Type IntentOptional Attributes Name
character(len=TIME_LEN), intent(in) :: time

ISO 8601 time stamp.

Return Value character(len=25)

public impure elemental function dm_time_to_beats(time, beats) result(rc)

Converts ISO 8601 time stamp time into Swatch Internet Time (.beat time) in the form @1000.00 in beats. One beat is equivalent to one decimal minute in the French decimal time (1 min 26.4 sec in Solar time).

Arguments

Type IntentOptional Attributes Name
character(len=TIME_LEN), intent(in) :: time

ISO 8601 time stamp.

character(len=8), intent(out) :: beats

Timestamp converted to .beat.

Return Value integer

public pure elemental function dm_time_to_human(time) result(human)

Returns time stamp as 26-characters long string in human-readable format. Converts the given ISO 8601 time stamp time in format 1970-01-01T00:00:00.000000+00:00 to format 1970-01-01 00:00:00 +00:00. The argument time is not validated. Make sure to only pass valid values.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=TIME_LEN), intent(in) :: time

ISO 8601 time stamp.

Return Value character(len=TIME_HUMAN_LEN)

Human-readable time stamp.

public impure elemental function dm_time_to_unix(time, epoch, useconds) result(rc)

Converts 32-characters long ISO 8601/RFC 3339 time stamp to Unix time stamp (Epoch). The function calls timegm() internally (not in POSIX, but available since 4.3BSD), and then removes the time zone offset. The returned Epoch is always in UTC. The output does not contain microseconds.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=TIME_LEN), intent(in) :: time

ISO 8601 time stamp.

integer(kind=i8), intent(out) :: epoch

Unix time stamp.

integer, intent(out), optional :: useconds

Additional microseconds.

Return Value integer

public pure elemental function dm_time_valid(time, strict) result(valid)

Returns .true. if given time stamp follows the form of ISO 8601. The time stamp does not have to be complete to be valid, unless strict is .true.. Then, argument time must be 32-characters long. Otherwise, the minimum length of a time stamp to be valid is 4 characters, the maximum is 32 characters.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: time

ISO 8601 time stamp to validate.

logical, intent(in), optional :: strict

Validate length (must be 32 characters).

Return Value logical

public function dm_time_zone() result(zone)

Returns current time zone as five characters long string, for example, +0000.

Arguments

None

Return Value character(len=5)

public function dm_time_zone_iso() result(zone)

Returns current time zone as six characters long string (ISO format), for example, +00:00.

Arguments

None

Return Value character(len=6)


Subroutines

public pure elemental subroutine dm_time_delta_from_seconds(time_delta, seconds)

Returns time delta type time_delta from Unix time stamp in seconds.

Arguments

Type IntentOptional Attributes Name
type(time_delta_type), intent(out) :: time_delta

Time delta type.

integer(kind=i8), intent(in) :: seconds

Unix time stamp (Epoch).

public subroutine dm_time_strings(year, month, day, hour, minute, second, usecond, zone_hour, zone_minute, zone)

Returns current date and time values as strings in given dummy arguments.

Arguments

Type IntentOptional Attributes Name
character(len=4), intent(out), optional :: year

Current year (YYYY).

character(len=2), intent(out), optional :: month

Current month (MM).

character(len=2), intent(out), optional :: day

Current day of month (DD).

character(len=2), intent(out), optional :: hour

Current hour (hh).

character(len=2), intent(out), optional :: minute

Current minute (mm).

character(len=2), intent(out), optional :: second

Current second (ss).

character(len=6), intent(out), optional :: usecond

Current usecond (ffffff).

character(len=3), intent(out), optional :: zone_hour

Current time zone ([+|-]hh).

character(len=2), intent(out), optional :: zone_minute

Current time zone (mm).

character(len=6), intent(out), optional :: zone

Current time zone ([+|-]hh:mm).