adacl_6.1.1_9615232c/src/adacl-calendar.ads

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
--------------------------------------------------------------- {{{1 ----------
--: Copyright © 2003 … 2023 Martin Krischik «krischik@users.sourceforge.net»
------------------------------------------------------------------------------
--: This library is free software; you can redistribute it and/or modify it
--: under the terms of the GNU Library General Public License as published by
--: the Free Software Foundation; either version 2 of the License, or (at your
--: option) any later version.
--:
--: This library is distributed in the hope that it will be useful, but
--: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
--: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
--: License for more details.
--:
--: You should have received a copy of the GNU Library General Public License
--: along with this library; if not, write to the Free Software Foundation,
--: Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
--------------------------------------------------------------- }}}1 ----------

pragma License (Modified_Gpl);
pragma Ada_2022;

with Ada.Calendar.Formatting;
with Ada.Characters.Conversions;

---
--  @summary
--  Some calendar utility functions.
--
--  @description
--  No, I have not created some new Calendar class - yet. Just a few calendar tools.
--
package AdaCL.Calendar is

   procedure Split_Duration
      (Seconds    :     Duration;
       Hour       : out Natural;
       Minute     : out Ada.Calendar.Formatting.Minute_Number;
       Second     : out Ada.Calendar.Formatting.Second_Number;
       Sub_Second : out Ada.Calendar.Formatting.Second_Duration);

   ---
   --  Convert a Day_Duration into Second_Number — which is basically the integer part of the duration
   --
   --: @param Duration to converut
   --: @return the Second_Number of the duration
   function To_Second_Number (Value : Ada.Calendar.Day_Duration) return Ada.Calendar.Formatting.Second_Number with
      Pure_Function;

   ---
   --  Convert a Day_Duration into Second_Duration — which is basically the fraction part of the duration
   --
   --: @param Duration to converut
   --: @return the Second_Duration of the duration
   function To_Second_Duration (Value : Ada.Calendar.Day_Duration) return Ada.Calendar.Formatting.Second_Duration with
      Pure_Function;

   ---
   --  Image representation with Fractional seconds.
   --
   --: @param Value value to create the image from
   --: @param Fraction_Digits amount of fractional digits to add.
   --
   function Date_Time_Image
      (Value           : Ada.Calendar.Time;
       Fraction_Digits : Natural := 1)
       return String with
      Pure_Function, Post => Date_Time_Image'Result'Length = 20 + Fraction_Digits;

   ---
   --  Wide image representation with Fractional seconds.
   --
   --: @param Value value to create the image from
   --: @param Fraction_Digits amount of fractional digits to add.
   --
   function Date_Time_Wide_Image
      (Value           : Ada.Calendar.Time;
       Fraction_Digits : Natural := 1)
       return Wide_String is
      (Ada.Characters.Conversions.To_Wide_String (Date_Time_Image (Value, Fraction_Digits))) with
      Pure_Function, Inline, Post => Date_Time_Wide_Image'Result'Length = 20 + Fraction_Digits;

   ---
   --  Wide wide image representation with Fractional seconds.
   --
   --: @param Value value to create the image from
   --: @param Fraction_Digits amount of fractional digits to add.
   --
   function Date_Time_Wide_Wide_Image
      (Value           : Ada.Calendar.Time;
       Fraction_Digits : Natural := 1)
       return Wide_Wide_String is
      (Ada.Characters.Conversions.To_Wide_Wide_String (Date_Time_Image (Value, Fraction_Digits))) with
      Pure_Function, Inline, Post => Date_Time_Wide_Wide_Image'Result'Length = 20 + Fraction_Digits;

   ---
   --  Image representation of a Duration in the form HHHH:MM:SStttt
   --
   --: @param Value value to create the image from
   --: @param Hour_Digits  amount of digits for the hour to add.
   --: @param Fraction_Digits amount of fractional digits to add.
   --
   function Duration_Image
      (Value           : Duration;
       Hour_Digits     : Positive := 4;
       Fraction_Digits : Natural  := 1)
       return String with
      Pure_Function,
      Pre  => Hour_Digits >= 2 and then Value <= 3_600.0 * (10**Hour_Digits),
      Post => Duration_Image'Result'Length = Hour_Digits + 7 + Fraction_Digits;

   ---
   --  Image representation of a Duration in the form HHHH:MM:SStttt
   --
   --: @param Value value to create the image from
   --: @param Hour_Digits  amount of digits for the hour to add.
   --: @param Fraction_Digits amount of fractional digits to add.
   --
   function Duration_Wide_Image
      (Value           : Duration;
       Hour_Digits     : Positive := 4;
       Fraction_Digits : Natural  := 1)
       return Wide_String is
      (Ada.Characters.Conversions.To_Wide_String (Duration_Image (Value, Hour_Digits, Fraction_Digits))) with
      Pure_Function,
      Inline,
      Pre  => Hour_Digits >= 2 and then Value <= 3_600.0 * (10**Hour_Digits),
      Post => Duration_Wide_Image'Result'Length = Hour_Digits + 7 + Fraction_Digits;

   ---
   --  Image representation of a Duration in the form HHHH:MM:SStttt
   --
   --: @param Value value to create the image from
   --: @param Hour_Digits  amount of digits for the hour to add.
   --: @param Fraction_Digits amount of fractional digits to add.
   --
   function Duration_Wide_Wide_Image
      (Value           : Duration;
       Hour_Digits     : Positive := 4;
       Fraction_Digits : Natural  := 1)
       return Wide_Wide_String is
      (Ada.Characters.Conversions.To_Wide_Wide_String (Duration_Image (Value, Hour_Digits, Fraction_Digits))) with
      Pure_Function,
      Inline,
      Pre  => Hour_Digits >= 2 and then Value <= 3_600.0 * (10**Hour_Digits),
      Post => Duration_Wide_Wide_Image'Result'Length = Hour_Digits + 7 + Fraction_Digits;

end AdaCL.Calendar;

---------------------------------------------------------------- {{{ ----------
--: vim: set textwidth=0 nowrap tabstop=8 shiftwidth=3 softtabstop=3 expandtab :
--: vim: set filetype=ada fileencoding=utf-8 fileformat=unix foldmethod=expr :
--: vim: set spell spelllang=en_gb