[Ada] New function to return nanoseconds from Unix Epoch
2018-05-29 Doug Rupp <rupp@adacore.com> gcc/ada/ * libgnat/a-calend.adb (Epoch_Offset): Move from body to ... * libgnat/a-calend.ads (Epoch_Offset): to private part of spec * libgnat/a-calcon.ads (To_Unix_Nano_Time): New function spec. * libgnat/a-calcon.adb (To_Unix_Nano_Time): New function body. From-SVN: r260870
This commit is contained in:
parent
0f9ca0303e
commit
35f5e2c14a
@ -1,3 +1,10 @@
|
||||
2018-05-29 Doug Rupp <rupp@adacore.com>
|
||||
|
||||
* libgnat/a-calend.adb (Epoch_Offset): Move from body to ...
|
||||
* libgnat/a-calend.ads (Epoch_Offset): to private part of spec
|
||||
* libgnat/a-calcon.ads (To_Unix_Nano_Time): New function spec.
|
||||
* libgnat/a-calcon.adb (To_Unix_Nano_Time): New function body.
|
||||
|
||||
2018-05-29 Eric Botcazou <ebotcazou@adacore.com>
|
||||
|
||||
* repinfo.ads (JSON format): Document new pair for components.
|
||||
|
@ -30,6 +30,7 @@
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
with Interfaces.C; use Interfaces.C;
|
||||
with Interfaces.C.Extensions; use Interfaces.C.Extensions;
|
||||
|
||||
package body Ada.Calendar.Conversions is
|
||||
|
||||
@ -145,4 +146,18 @@ package body Ada.Calendar.Conversions is
|
||||
return long (Val);
|
||||
end To_Unix_Time;
|
||||
|
||||
-----------------------
|
||||
-- To_Unix_Nano_Time --
|
||||
-----------------------
|
||||
|
||||
function To_Unix_Nano_Time (Ada_Time : Time) return long_long is
|
||||
pragma Unsuppress (Overflow_Check);
|
||||
Ada_Rep : constant Time_Rep := Time_Rep (Ada_Time);
|
||||
begin
|
||||
return long_long (Ada_Rep + Epoch_Offset);
|
||||
exception
|
||||
when Constraint_Error =>
|
||||
raise Time_Error;
|
||||
end To_Unix_Nano_Time;
|
||||
|
||||
end Ada.Calendar.Conversions;
|
||||
|
@ -33,6 +33,7 @@
|
||||
-- time models - Time, Duration, struct tm and struct timespec.
|
||||
|
||||
with Interfaces.C;
|
||||
with Interfaces.C.Extensions;
|
||||
|
||||
package Ada.Calendar.Conversions is
|
||||
|
||||
@ -110,4 +111,11 @@ package Ada.Calendar.Conversions is
|
||||
-- units of the result are seconds. Raises Time_Error if the result cannot
|
||||
-- fit into a Time value.
|
||||
|
||||
function To_Unix_Nano_Time (Ada_Time : Time) return
|
||||
Interfaces.C.Extensions.long_long;
|
||||
-- Convert a time value represented as number of time units since the Ada
|
||||
-- implementation-defined Epoch to a value relative to the Unix Epoch. The
|
||||
-- units of the result are nanoseconds. Raises Time_Error if the result
|
||||
-- cannot fit into a Time value.
|
||||
|
||||
end Ada.Calendar.Conversions;
|
||||
|
@ -203,10 +203,6 @@ is
|
||||
Ada_Low + Time_Rep (34 * 366 + 102 * 365) * Nanos_In_Day +
|
||||
Time_Rep (Leap_Seconds_Count) * Nano;
|
||||
|
||||
Epoch_Offset : constant Time_Rep := (136 * 365 + 44 * 366) * Nanos_In_Day;
|
||||
-- The difference between 2150-1-1 UTC and 1970-1-1 UTC expressed in
|
||||
-- nanoseconds. Note that year 2100 is non-leap.
|
||||
|
||||
Cumulative_Days_Before_Month :
|
||||
constant array (Month_Number) of Natural :=
|
||||
(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
|
||||
|
@ -221,6 +221,10 @@ private
|
||||
-- with overloading ambiguities in the body if we tried to use Time as an
|
||||
-- internal computational type.
|
||||
|
||||
Epoch_Offset : constant Time_Rep := (136 * 365 + 44 * 366) * Nanos_In_Day;
|
||||
-- The difference between 2150-1-1 UTC and 1970-1-1 UTC expressed in
|
||||
-- nanoseconds. Note that year 2100 is non-leap.
|
||||
|
||||
Days_In_Month : constant array (Month_Number) of Day_Number :=
|
||||
(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
|
||||
-- Days in month for non-leap year, leap year case is adjusted in code
|
||||
|
Loading…
Reference in New Issue
Block a user