Language Change Specification for Date and Time

LCS Number: LCS-2016-11
Version: 2
Date: 17-Nov-2016
Status: Approved
Author: Rob Gaddi
Source Doc: DateTime
More: History
Summary: Provide system date/time mechanism in std.env

Details of Language Change

Changes are shown in red font.

Section 16.5 Standard environment package

011.1: Bottom page 274


package ENV is

procedure STOP (STATUS: INTEGER);
procedure STOP;

procedure FINISH (STATUS: INTEGER);
procedure FINISH;

function RESOLUTION_LIMIT return DELAY_LENGTH;

type DAYOFWEEK is (
 SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, 
 FRIDAY, SATURDAY
);

-- Calendar date/time, broken into parts.  Second accomodates both
-- single and double leap-seconds.  Dayofyear accomodates leap days.
-- Month 0 is January, 1 is February, 11 is December. Year is absolute
-- in AD, 1900 represents the year 1900.
--
type TIME_RECORD is record
 microsecond : INTEGER range 0 to 999_999
 second : INTEGER range 0 to 61;
 minute : INTEGER range 0 to 59;
 hour : INTEGER range 0 to 23;
 day : INTEGER range 1 to 31;
 month : INTEGER range 0 to 11;
 year : INTEGER range 1 to 4095;
 weekday : DAYOFWEEK;
 dayofyear : INTEGER range 0 to 365;
end record TIME_RECORD;

-- Current local time broken into parts.
-- Minimum legal resolution is 1 second.
impure function LOCALTIME return TIME_RECORD;

-- Current UTC time broken into parts.
-- Minimum legal resolution is 1 second.
impure function GMTIME return TIME_RECORD;

-- Number of seconds since midnight, Jan 1 1970, UTC.
-- Minimum legal resolution is 1 second.
impure function EPOCH return REAL;

-- Time conversion functions from epoch time.
function LOCALTIME(TIMER: REAL) return TIME_RECORD;
function GMTIME(TIMER: REAL) return TIME_RECORD;

-- Time conversion function from time in parts.
-- EPOCH and GMTIME accept TREC in local time.
-- LOCALTIME accepts TREC in UTC.
function EPOCH(TREC: TIME_RECORD) return REAL;
function LOCALTIME(TREC: TIME_RECORD) return TIME_RECORD;
function GMTIME(TREC: TIME_RECORD) return TIME_RECORD;

-- Time increment/decrement.  DELTA argument is in seconds.
-- Returned TIME_RECORD is in local time or UTC per the TREC.
function "+"(TREC: TIME_RECORD; DELTA: REAL) return TIME_RECORD;
function "+"(DELTA: REAL; TREC: TIME_RECORD) return TIME_RECORD;
function "-"(TREC: TIME_RECORD; DELTA: REAL) return TIME_RECORD;
function "-"(DELTA: REAL; TREC: TIME_RECORD) return TIME_RECORD;

-- Time difference in seconds.  TR1, TR2 must both be in local
-- time, or both in UTC.
function "-"(TR1, TR2: TIME_RECORD) return REAL;

-- Conversion between real seconds and VHDL TIME.  SECONDS_TO_TIME
-- will cause an error if the resulting REAL_VAL would be less than
-- TIME'LOW or greater than TIME'HIGH.
function TIME_TO_SECONDS(TIME_VAL: IN TIME) return REAL;
function SECONDS_TO_TIME(REAL_VAL: IN REAL) return TIME;

-- Convert TIME_RECORD to a string in ISO 8601 format.
-- TO_STRING(x)    => "1973-09-16T01:03:52"
-- TO_STRING(x, 6) => "1973-09-16T01:03:52.000001"
function TO_STRING(TREC: TIME_RECORD, FRAC_DIGITS: INTEGER range 0 to 6 := 0) return STRING;

end package ENV;

011.2: Middle page 275

The function RESOLUTION_LIMIT returns the value of the resolution limit (see 5.2.4.2). The function EPOCH translates a TIME_RECORD representing local time into so-called "epoch time", i.e. the number of seconds since midnight, Jan 1 1970 UTC, or when called without arguments returns the current time in the same form. The minimum resolution allowed is one second.

The function LOCALTIME translates an epoch time into a TIME_RECORD representing a time in the local timezone, translates a TIME_RECORD representing a time in UTC into one in the local timezone, or when called without arguments returns a TIME_RECORD representing the current time in the local timezone. Local timezone is determined in a manner determined by the host system. The minimum resolution allowed is one second.

The function GMTIME translates an epoch time into a TIME_RECORD respresenting a time in UTC, translates a TIME_RECORD representing a time in the local timezone into one in UTC, or when called without arguments returns a TIME_RECORD representing the current time in UTC. The minimum resolution allowed is one second.

Objects of type TIME_RECORD support addition and subtraction of numbers of seconds as represented by REAL numbers, and the difference between two TIME_RECORDS can be taken as a number of seconds, represented as a REAL.

The TO_STRING operation returns the string representation (see 5.7) of the value of its actual parameter of type TIME_RECORD. The resulting string will specify the time in ISO 8601 format and will consist of the concatenation of the following, in order:

  • The YEAR element expressed in 4 decimal digits
  • A '-' character
  • The MONTH element + 1 expressed in 2 decimal digits (01 through 12)
  • A '-' character
  • The DAY element expressed in 2 decimal digits
  • A 'T' character
  • The HOUR element expressed in 2 decimal digits
  • A ':' character
  • The MINUTE element expressed in 2 decimal digits
  • A ':' character
  • The SECOND element expressed in 2 decimal digits
  • The MICROSECOND element expressed in a manner defined by the DIGITS parameter.

The DIGITS parameter specifies the number of digits that the MICROSECOND element will be truncated to. If the DIGITS parameter is zero (the default) then the MICROSECOND element will be absent in the resultant string. If DIGITS is 1-6, the MICROSECOND element will appear as a '.' character followed by DIGITS of the most significant decimal digits

The function TIME_TO_SECONDS translates objects of type TIME into a REAL approximation of the number of seconds. TIME_TO_SECONDS(1 sec) returns REAL'(1.0).

The function SECONDS_TO_TIME translates a REAL number of seconds into an approximation in type TIME. SECONDS_TO_TIME(1.0) returns TIME'(1 sec). Neither TIME_TO_SECONDS(SECONDS_TO_TIME(x)) nor SECONDS_TO_TIME(TIME_TO_SECONDS(x)) is guaranteed to yield an output that is exactly equal to the input.

Notes 1-3 are unchanged

Note 4 - Simulators should return the current system time whenever the EPOCH, LOCALTIME, or GMTIME functions are called without argument. Synthesis tools should return the time of compilation, which may be treated as a constant.

Comments

Topic revision: r29 - 2017-07-23 - 20:55:17 - RobGaddi
 
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback