--------------------------------------------------------------- {{{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