foresight_time
foresight_time, gnuplot's time values: seconds since 1970-01-01 00:00 UTC, written and read as gnuplot 6.0's
strftimeandstrptimedo.
Dates are proleptic Gregorian, without leap seconds or time zones, as gnuplot's. The conversions are gnuplot's own (gstrftime, gstrptime), not C's: %p writes am/pm, %.3S writes fractional seconds, %tH, %tM, %tS write and read elapsed times; a conversion gnuplot does not know writes nothing.
Source: src/lib/foresight_time.F90
Dependencies
Contents
- civil_from_days
- time_parts
- strptime
- days_from_civil
- civil_time
- now_seconds
- strftime
- time_format_check
- time_justify
- padded
- decimals
- lower
Variables
| Name | Type | Attributes | Description |
|---|---|---|---|
DAY_SEC | real(kind=R8P) | parameter | Seconds of a day. |
WEEK_SEC | real(kind=R8P) | parameter | Seconds of a week. |
YEAR_SEC | real(kind=R8P) | parameter | Seconds of a mean year (gnuplot's). |
MON_SEC | real(kind=R8P) | parameter | Seconds of a mean month (gnuplot's). |
DAY_NAMES | character(len=9) | parameter | Weekday names. |
MONTH_NAMES | character(len=9) | parameter | Month names. |
Subroutines
civil_from_days
The date of days since 1970-01-01 (H. Hinnant's algorithm).
Attributes: pure
subroutine civil_from_days(days, y, m, d)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
days | integer(kind=I8P) | in | Days since the epoch. | |
y | integer(kind=I8P) | out | Year. | |
m | integer(kind=I8P) | out | Month, 1 for January. | |
d | integer(kind=I8P) | out | Day of the month, from 1. |
Call graph
time_parts
The broken-down time of t [s since the epoch]: yday the day of the year from 1, wday the weekday from 0 (Sunday); second whole, fraction the rest of it (in [0, 1)).
Attributes: pure
subroutine time_parts(t, year, month, day, hour, minute, second, fraction, yday, wday)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
t | real(kind=R8P) | in | Time [s]. | |
year | integer(kind=I8P) | out | Year. | |
month | integer(kind=I8P) | out | Month, 1 for January. | |
day | integer(kind=I8P) | out | Day of the month, from 1. | |
hour | integer(kind=I8P) | out | Hour. | |
minute | integer(kind=I8P) | out | Minute. | |
second | integer(kind=I8P) | out | Second. | |
fraction | real(kind=R8P) | out | Fraction of the second. | |
yday | integer(kind=I8P) | out | Day of the year, from 1. | |
wday | integer(kind=I8P) | out | Weekday, 0 Sunday. |
Call graph
strptime
text read with the time format, as gnuplot's strptime: %d %m %H %M (up to 2 digits), %y (2 digits, 69 to 99 the 1900s, else the 2000s), %Y (up to 4), %j (up to 3), %S (seconds with a fraction), %s (seconds since the epoch), %b %B (month names or their 3 first letters), %a %A (weekday names, skipped), %p (pm adds 12 hours), %tH %tM %tS (elapsed hours, minutes, seconds, signed, the last with a fraction), %z (a zone offset, Z or [+-]hh[:]mm, taken off), %Z (a zone name, skipped); a blank matches any run of blanks, any other character itself. Fields not given are those of 1970-01-01 00:00:00, also those after the end of the text (gnuplot reads "1/6/93" with "%d/%m/%y %H%M"). ok false (t NaN) if text does not match. Sign of the offset. Hours. Minutes. Read status.
Attributes: pure
subroutine strptime(format, text, t, ok)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
format | character(len=*) | in | Time format. | |
text | character(len=*) | in | Text. | |
t | real(kind=R8P) | out | Time [s]. | |
ok | logical | out | Text matched. |
Call graph
Functions
days_from_civil
Days from 1970-01-01 to the date y-m-d (H. Hinnant's algorithm; m and d may overflow their ranges).
Attributes: pure
Returns: integer(kind=I8P)
function days_from_civil(y, m, d) result(days)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
y | integer(kind=I8P) | in | Year. | |
m | integer(kind=I8P) | in | Month, 1 for January. | |
d | integer(kind=I8P) | in | Day of the month, from 1. |
Call graph
civil_time
Seconds since the epoch of a date and time (fields may overflow their ranges, as mktime's).
Attributes: pure
Returns: real(kind=R8P)
function civil_time(year, month, day, hour, minute, second) result(t)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
year | integer(kind=I8P) | in | Year. | |
month | integer(kind=I8P) | in | Month, 1 for January. | |
day | integer(kind=I8P) | in | Day of the month, from 1. | |
hour | integer(kind=I8P) | in | Hour. | |
minute | integer(kind=I8P) | in | Minute. | |
second | real(kind=R8P) | in | Second, with its fraction. |
Call graph
now_seconds
The time now as seconds since the epoch of the local wall clock (gnuplot set timestamp), or the environment's SOURCE_DATE_EPOCH when set (reproducible output, beyond gnuplot).
Returns: real(kind=R8P)
function now_seconds() result(t)Call graph
strftime
t [s since the epoch] written with the time format, as gnuplot's strftime: %a %A %b %B %h names, %d %m %y %Y %j %H %I %M %S numbers (zero padded), %k %l hours (blank padded), %p am/pm, %s the seconds since the epoch, %w the weekday number, %U %W week numbers, %D (%m/%d/%y), %F (%Y-%m-%d), %T (%H:%M:%S), %R (%H:%M), %r (%I:%M:%S %p), %.NS the seconds with N decimals, %tH %tM %tS the elapsed hours, minutes, seconds (the largest unit present unbounded), %%; others write nothing.
Attributes: pure
Returns: character(len=:)
function strftime(format, t) result(text)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
format | character(len=*) | in | Time format. | |
t | real(kind=R8P) | in | Time [s]. |
Call graph
time_format_check
Empty if format is a time format: text whose % conversions are among those strftime knows (a gnuplot set format x "%H:%M" on a time axis); else the problem.
Attributes: pure
Returns: character(len=:)
function time_format_check(format) result(message)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
format | character(len=*) | in | Format. |
Call graph
time_justify
t moved to a whole time unit of the tick level (0 seconds, 1 minutes, 2 hours, 3 days, 4 weeks, 5 months, 6 years), as gnuplot's time_tic_just: days and longer at 0 AM, minutes and hours rounded up past 55, months to the 1st (the next month past the 25th).
Attributes: pure
Returns: real(kind=R8P)
function time_justify(level, t) result(justified)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
level | integer(kind=I4P) | in | Tick level. | |
t | real(kind=R8P) | in | Time [s]. |
Call graph
padded
n in decimal, padded on the left with pad to width characters (a minus sign first).
Attributes: pure
Returns: character(len=:)
function padded(n, width, pad) result(text)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
n | integer(kind=I8P) | in | Number. | |
width | integer(kind=I4P) | in | Least width. | |
pad | character(len=1) | in | Padding character. |
Call graph
decimals
. then prec decimals of fraction (in [0, 1)), rounded and never carried (at most 0.99...), as gnuplot 6.0's %.NS (time.c: floor(0.5 + 10**prec * fraction), capped).
Attributes: pure
Returns: character(len=:)
function decimals(fraction, prec) result(text)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
fraction | real(kind=R8P) | in | Fraction. | |
prec | integer(kind=I4P) | in | Decimals. |
Call graph
lower
text in lower case.
Attributes: pure
Returns: character(len=len)
function lower(text) result(low)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
text | character(len=*) | in | Text. |
Call graph