]>
Commit | Line | Data |
---|---|---|
6e451134 HK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT RUN-TIME COMPONENTS -- | |
4 | -- -- | |
5 | -- A D A . C A L E N D A R . A R I T H M E T I C -- | |
6 | -- -- | |
7 | -- B o d y -- | |
8 | -- -- | |
4b490c1e | 9 | -- Copyright (C) 2006-2020, Free Software Foundation, Inc. -- |
6e451134 HK |
10 | -- -- |
11 | -- GNAT is free software; you can redistribute it and/or modify it under -- | |
12 | -- terms of the GNU General Public License as published by the Free Soft- -- | |
748086b7 | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
6e451134 HK |
14 | -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
15 | -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- | |
748086b7 JJ |
16 | -- or FITNESS FOR A PARTICULAR PURPOSE. -- |
17 | -- -- | |
18 | -- As a special exception under Section 7 of GPL version 3, you are granted -- | |
19 | -- additional permissions described in the GCC Runtime Library Exception, -- | |
20 | -- version 3.1, as published by the Free Software Foundation. -- | |
21 | -- -- | |
22 | -- You should have received a copy of the GNU General Public License and -- | |
23 | -- a copy of the GCC Runtime Library Exception along with this program; -- | |
24 | -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- | |
25 | -- <http://www.gnu.org/licenses/>. -- | |
6e451134 HK |
26 | -- -- |
27 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
28 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- | |
29 | -- -- | |
30 | ------------------------------------------------------------------------------ | |
31 | ||
6e451134 HK |
32 | package body Ada.Calendar.Arithmetic is |
33 | ||
42907632 HK |
34 | -------------------------- |
35 | -- Implementation Notes -- | |
36 | -------------------------- | |
6e451134 | 37 | |
42907632 HK |
38 | -- All operations in this package are target and time representation |
39 | -- independent, thus only one source file is needed for multiple targets. | |
6e451134 HK |
40 | |
41 | --------- | |
42 | -- "+" -- | |
43 | --------- | |
44 | ||
45 | function "+" (Left : Time; Right : Day_Count) return Time is | |
42907632 | 46 | R : constant Long_Integer := Long_Integer (Right); |
6e451134 | 47 | begin |
42907632 | 48 | return Arithmetic_Operations.Add (Left, R); |
6e451134 HK |
49 | end "+"; |
50 | ||
51 | function "+" (Left : Day_Count; Right : Time) return Time is | |
42907632 | 52 | L : constant Long_Integer := Long_Integer (Left); |
6e451134 | 53 | begin |
42907632 | 54 | return Arithmetic_Operations.Add (Right, L); |
6e451134 HK |
55 | end "+"; |
56 | ||
57 | --------- | |
58 | -- "-" -- | |
59 | --------- | |
60 | ||
61 | function "-" (Left : Time; Right : Day_Count) return Time is | |
42907632 | 62 | R : constant Long_Integer := Long_Integer (Right); |
6e451134 | 63 | begin |
42907632 | 64 | return Arithmetic_Operations.Subtract (Left, R); |
6e451134 HK |
65 | end "-"; |
66 | ||
67 | function "-" (Left, Right : Time) return Day_Count is | |
42907632 | 68 | Days : Long_Integer; |
6e451134 | 69 | Seconds : Duration; |
42907632 | 70 | Leap_Seconds : Integer; |
67ce0d7e RD |
71 | pragma Warnings (Off, Seconds); -- temporary ??? |
72 | pragma Warnings (Off, Leap_Seconds); -- temporary ??? | |
73 | pragma Unreferenced (Seconds, Leap_Seconds); | |
6e451134 | 74 | begin |
42907632 HK |
75 | Arithmetic_Operations.Difference |
76 | (Left, Right, Days, Seconds, Leap_Seconds); | |
77 | return Day_Count (Days); | |
6e451134 HK |
78 | end "-"; |
79 | ||
80 | ---------------- | |
81 | -- Difference -- | |
82 | ---------------- | |
83 | ||
84 | procedure Difference | |
42907632 HK |
85 | (Left : Time; |
86 | Right : Time; | |
6e451134 HK |
87 | Days : out Day_Count; |
88 | Seconds : out Duration; | |
89 | Leap_Seconds : out Leap_Seconds_Count) | |
90 | is | |
42907632 HK |
91 | Op_Days : Long_Integer; |
92 | Op_Leaps : Integer; | |
6e451134 | 93 | begin |
42907632 HK |
94 | Arithmetic_Operations.Difference |
95 | (Left, Right, Op_Days, Seconds, Op_Leaps); | |
96 | Days := Day_Count (Op_Days); | |
97 | Leap_Seconds := Leap_Seconds_Count (Op_Leaps); | |
6e451134 HK |
98 | end Difference; |
99 | ||
100 | end Ada.Calendar.Arithmetic; |