Lightweight, high-performance date/time handling for the fpx preprocessor This module provides a compact datetime type and essential operations used primarily for expanding the standard predefined macros:
__DATE__ → e.g. 'Aug-12-2025'
__TIME__ → e.g. '14:35:27'
__TIMESTAMP__ → e.g. 'Tue 12-Aug-2025 14:35:27'
Features:
now() returns current local date/time using date_and_time()
- Flexible string formatting via
to_string(fmt)
- Parsing from common string formats (ISO, US, RFC-like)
- Day-of-week calculation via Zeller’s congruence
- Elemental and pure functions where possible for performance
- Minimal memory footprint using small integer kinds (
int8, int16)
Used internally by fpx_macro during __DATE__, __TIME__, and __TIMESTAMP__ expansion.
- Expand standard predefined macros (as done internally):
type(datetime) :: dt
dt = now()
print *, '__DATE__ >> ', dt%to_string('MMM-dd-yyyy')
print *, '__TIME__ >> ', dt%to_string('HH:mm:ss')
print *, '__TIMESTAMP__ >> ', dt%to_string('ddd-MMM-yyyy HH:mm:ss')
...
- Parse date from string:
type(datetime) :: build_time
build_time = datetime('2025-08-12 09:30:00')
print *, 'build on: ', build_time%to_string('ddd-MMM-yyyy')
...
- Get current time for logging:
type(datetime) :: dt
dt = now()
print *, 'Preprocessing started at ', dt%to_string('HH:mm:ss')
...
|
| type | datetime |
| | Compact representation of date and time Stores all components in minimal integer kinds to reduce memory usage. All fields are public for easy access. More...
|
| |
◆ datetime_parse()
| elemental subroutine datetime_parse |
( |
class(datetime), intent(inout) | this, |
|
|
character(*), intent(in) | string, |
|
|
character(*), intent(in), optional | fmt ) |
|
private |
Parse date/time from string using common formats.
Supports ISO, US, and abbreviated month formats. On error, defaults to Unix epoch (1970-01-01 00:00:00) Perform conversion to ISO string
- d: Represents the day of the month as a number from 1 through 31.
- dd: Represents the day of the month as a number from 01 through 31.
- ddd: Represents the abbreviated name of the day (Mon, Tues, Wed, etc).
- dddd: Represents the full name of the day (Monday, Tuesday, etc).
- h: 12-hour clock hour (e.g. 4).
- hh: 12-hour clock, with a leading 0 (e.g. 06)
- H: 24-hour clock hour (e.g. 15)
- HH: 24-hour clock hour, with a leading 0 (e.g. 22)
- m: Minutes
- mm: Minutes with a leading zero
- M: Month number(eg.3)
- MM: Month number with leading zero(eg.04)
- MMM: Abbreviated Month Name (e.g. Dec)
- MMMM: Full month name (e.g. December)
- s: Seconds
- ss: Seconds with leading zero
- t: Abbreviated AM / PM (e.g. A or P)
- tt: AM / PM (e.g. AM or PM
- y: Year, no leading zero (e.g. 2015 would be 15)
- yy: Year, leading zero (e.g. 2015 would be 015)
- yyy: Year, (e.g. 2015)
- yyyy: Year, (e.g. 2015)
Remarks
Definition at line 243 of file date.f90.
◆ datetime_to_string()
| character(:) function, allocatable datetime_to_string |
( |
class(datetime), intent(in) | this, |
|
|
character(*), intent(in), optional | fmt ) |
|
private |
Format datetime as string using flexible format codes Supports many common patterns including those required for __DATE__ and __TIMESTAMP__. Default format: 'yyyy-MM-ddTHH:mm:ss'.
Remarks
Definition at line 357 of file date.f90.
◆ now()
Return current local date and time Uses intrinsic date_and_time() and populates all fields including milliseconds.
- Returns
- the datetime object corresponding to the current time
Remarks
Definition at line 164 of file date.f90.
◆ weekday()
| pure elemental integer function weekday |
( |
class(datetime), intent(in) | this | ) |
|
|
private |
Returns the day of the week calculated using Zeller's congruence. Returned value is an integer scalar in the range [0-6], such that:
- 0: Sunday
- 1: Monday
- 2: Tuesday
- 3: Wednesday
- 4: Thursday
- 5: Friday
- 6: Saturday
Remarks
Definition at line 192 of file date.f90.