ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
calendar.hpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header file is part of sub-namespace #alib::lang::system of module \alib_basecamp of
4/// the \aliblong.
5///
6/// \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
7/// Published under \ref mainpage_license "Boost Software License".
8//==================================================================================================
9#ifndef HPP_ALIB_LANG_SYSTEM_CALENDAR
10#define HPP_ALIB_LANG_SYSTEM_CALENDAR 1
11#pragma once
15
16#include "alib/time/ticks.hpp"
19
20
21namespace alib { namespace lang::system {
22
23//==================================================================================================
24/// This class represents a point in time as a set of calendar and clock values
25/// (year, month, day, hour, ...).
26/// It provides methods to convert to and from objects of type \alib{time;DateTime}.
27/// In addition, a method to format the date and time into human-readable string value is available.
28///
29/// \note
30/// The conversion from and into objects of type \alib{time;Ticks} is intentionally not supported.
31/// In the case that such objects should be used with this class, an additional conversion
32/// step has to be performed using class \alib{time;TickConverter}. In other words, conversion can
33/// be performed as follows:
34///
35/// CalendarDateTime <=> DateTime <=> Ticks
36/// <p>
37/// \note
38/// This class is using system specific calendar methods and relies on the locale and time zone
39/// settings of the machine.
40///
41/// <p>
42/// \note
43/// This class is part of sub-namespace alib::lang::format of module \alib_basecamp. While it is a
44/// pure utility class for type \alib{time;DateTime} found in module \alib_time, the class was
45/// located there to keep module \b %Time lean and free from dependencies to module \alib_basecamp.
46//==================================================================================================
48{
49 public:
50 /// The calendar year (e.g., 2022).
51 int Year;
52
53 /// The calendar month (1..12).
54 int Month;
55
56 /// The calendar day (1..31).
57 int Day;
58
59 /// The calendar hour (0..23).
60 int Hour;
61
62 /// The calendar minute (0..59).
63 int Minute;
64
65 /// The calendar second (0..59).
66 int Second;
67
68 /// The calendar millisecond (0..999).
70
71 /// The calendar day of week (0==Sunday..6==Saturday).
72 /// \attention This value is only set when constructed with a \b DateTime object and
73 /// set to \c -1 if constructed with single values, or if method #Clear is
74 /// invoked.
76 //==============================================================================================
77 /// Constructs an unset object.
78 /// @param init If \b Initialization::Default or \b nulled, #Clear is invoked.
79 /// Otherwise fields are not initialized.
80 /// Defaults to \c Initialization::Default.
81 //==============================================================================================
87
88 //==============================================================================================
89 /// Constructs the object according to the given timestamp object and time zone.
90 /// @param timeStamp The point in time to use for setting the public fields
91 /// @param timezone Denotes if the time that is calculated should be local or UTC.
92 /// Defaults to \c TimeZone::Local.
93 //==============================================================================================
95 {
96 Set( timeStamp, timezone );
97 }
98
99 //==============================================================================================
100 /// Constructs the object according to the given date and time values.
101 /// @param year The year of the calendar time.
102 /// @param month The month of the calendar time.
103 /// @param day The day of the calendar time.
104 /// @param hour The hour of the calendar time.
105 /// @param minute The minute of the calendar time.
106 /// @param second The second of the calendar time.
107 /// @param millisecond The millisecond of the calendar time.
108 //==============================================================================================
109 CalendarDateTime( int year , int month= 1 , int day= 1,
110 int hour= 0, int minute= 0, int second= 0, int millisecond= 0 )
111 : Year ( year )
112 , Month ( month )
113 , Day ( day )
114 , Hour ( hour )
115 , Minute ( minute )
116 , Second ( second )
117 , Millisecond ( millisecond)
118 , DayOfWeek ( -1 )
119 {}
120
121 //==============================================================================================
122 /// Sets the public fields according to the given timestamp object.
123 /// @param timeStamp The point in time to use for setting the public fields
124 /// @param timezone Denotes if the time that is calculated should be local or UTC.
125 /// Defaults to \c TimeZone::Local.
126 //==============================================================================================
128 void Set( const DateTime& timeStamp, lang::Timezone timezone =lang::Timezone::Local );
129
130 //==============================================================================================
131 /// Creates a \b DateTime object from this calendar date.
132 /// \attention
133 /// The resolution and possible time range of class \b %DateTime is platform-dependent.
134 /// This method must not be used if inconsistent values are stored.
135 ///
136 /// @param timezone Denote if the time that is calculated should be local or UTC.
137 /// Defaults to \c TimeZone::Local.
138 /// @returns The point in time represented by the public fields of this class.
139 //==============================================================================================
142
143 //==============================================================================================
144 /// Sets all public values to \c 0.
145 //==============================================================================================
147 void Clear();
148
149 //==============================================================================================
150 /// Formats the date using a given pattern string. Within the pattern string, different symbols
151 /// are interpreted as tokens. The format is compatible with C# time format strings, as well as
152 /// with class SimpleDateFormat of the Java APIs.<br>
153 /// Strings within the format text that should not be interpreted as tokens may be surrounded
154 /// by single quotes.
155 /// Strings within the format text that should not be interpreted as tokens may be given
156 /// in single quotes.
157 /// Two consecutive single quotes will be replaced to one single quote.<br>
158 ///
159 /// <center>Token</center> | <center>Description</center>
160 /// - - - - -| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
161 /// y |The year with as many digits as it has (for current dates this is 4).</TD> </TR>
162 /// yy |The year, truncated to 2 digits (modulo 100).</TD> </TR>
163 /// yyy...y |The year with a minimum amount of digits as amount of y-characters given.</TD> </TR>
164 /// M |The month as numbers from 1..12.</TD> </TR>
165 /// MM |The month as numbers from 01..12.</TD> </TR>
166 /// MMM |The month as abbreviated, 3-digit word defined by resourced strings (defaults to English language).</TD> </TR>
167 /// MMMM |The month as word defined by resourced strings (defaults to English language).</TD> </TR>
168 /// d |The day as numbers from 1..31.</TD> </TR>
169 /// dd |The day as numbers from 01..31.</TD> </TR>
170 /// ddd |The day as abbreviated, 3-digit word defined by resourced strings (defaults to English language).</TD> </TR>
171 /// dddd |The day as word defined by resourced strings (defaults to English language).</TD> </TR>
172 /// H |The hour as numbers from 0..23.</TD> </TR>
173 /// HH |The hour as numbers from 00..23.</TD> </TR>
174 /// K |The hour as numbers from 0..11 am/pm.</TD> </TR>
175 /// KK |The hour as numbers from 00..11 am/pm.</TD> </TR>
176 /// m |The minute as numbers from 0..59.</TD> </TR>
177 /// mm |The minute as numbers from 00..59.</TD> </TR>
178 /// s |The second as numbers from 0..59.</TD> </TR>
179 /// ss |The second as numbers from 00..59.</TD> </TR>
180 ///
181 /// @param format The format pattern string.
182 /// @param target A reference to an AString that gets the result of the format processing
183 /// appended.
184 /// @param targetData If \c CurrentData::Keep (the default) the string is appended to \p{target}.
185 /// if \c CurrentData::Clear, \p{target} is cleared.
186 /// @returns \p{target} (for convenience).
187 //==============================================================================================
189 AString& Format( Substring format, AString& target,
191};
192
193//==================================================================================================
194/// This class represents a time span, measured in human units like days, hours, minutes and so on.
195/// Besides conversion from and to nanoseconds, conversions from and to objects of types
196/// \alib{time;TimePointBase::Duration;DateTime::Duration} and
197/// \alib{time;TimePointBase::Duration;Ticks::Duration} is supported.
198///
199/// \note
200/// This class is part of sub-namespace alib::lang::format of module \alib_basecamp. While it is a
201/// pure utility class for type \alib{time;DateTime} and \alib{time;Ticks} found in module found
202/// \alib_time, the class was located there to keep module \alib_time_nl lean and free from
203/// dependencies to module \alib_basecamp.
204//==================================================================================================
206{
207 public:
208 /// The number of days within the duration
209 int Days;
210
211 /// The number of hours (not the total, hence 0-23) within the duration.
212 int Hours;
213
214 /// The number of minutes (not the total, hence 0-59) within the duration.
216
217 /// The number of seconds (not the total, hence 0-59) within the duration.
219
220 /// The number of milliseconds (not the total, hence 0-999) within the duration.
222
223 /// The number of microseconds (not the total, hence 0-999) within the duration.
225
226 /// The number of nanoseconds (not the total, hence 0-999) within the duration.
228
229 //==============================================================================================
230 /// Constructs the object to represent a duration of 0. (Sets all public fields to 0.)
231 /// @param init If \b Initialization::Default or \b Nulled, #Clear is invoked.
232 /// Otherwise fields are not initialized.
233 /// Defaults to \b Initialization::Default.
234 //==============================================================================================
240
241 //==============================================================================================
242 /// Constructs the object using the given duration measured in nanoseconds.
243 /// Invokes #FromNanoSeconds.
244 /// @param nanos The duration to use for setting the public fields.
245 //==============================================================================================
246 CalendarDuration( int64_t nanos )
247 {
248 FromNanoSeconds( nanos );
249 }
250
251 //==============================================================================================
252 /// Constructs the object using the given duration object.
253 /// Invokes #FromDuration.
254 /// @param duration The duration to use for setting the public fields.
255 //==============================================================================================
256 CalendarDuration( DateTime::Duration duration )
257 {
258 FromDuration( duration );
259 }
260
261 //==============================================================================================
262 /// Constructs the object using the given duration object.
263 /// Invokes #FromDuration.
264 /// @param duration The duration to use for setting the public fields.
265 //==============================================================================================
266 CalendarDuration( Ticks::Duration duration )
267 {
268 FromDuration( duration );
269 }
270
271 //==============================================================================================
272 /// Sets the public fields to represent the given duration value.
273 /// The state of the object will hereafter be the same as it was when constructed with the same
274 /// parameter.
275 /// @param duration The duration to use for setting the public fields.
276 //==============================================================================================
277 void FromDuration( DateTime::Duration duration )
278 {
279 FromNanoSeconds( duration.InNanoseconds() );
280 }
281
282 //==============================================================================================
283 /// Sets the public fields to represent the given duration value.
284 /// The state of the object will hereafter be the same as it was when constructed with the same
285 /// parameter.
286 /// @param duration The duration to use for setting the public fields.
287 //==============================================================================================
288 void FromDuration( Ticks::Duration duration )
289 {
290 FromNanoSeconds( duration.InNanoseconds() );
291 }
292
293 //==============================================================================================
294 /// Takes the current values of the public fields and returns a duration value compatible with
295 /// class \b %DateTime.
296 /// @returns The duration represented by the public fields of this class.
297 //==============================================================================================
298 DateTime::Duration ToDateTimeDuration()
299 {
300 return DateTime::Duration::FromNanoseconds( ToNanoSeconds() );
301 }
302
303 //==============================================================================================
304 /// Takes the current values of the public fields and returns a duration value compatible with
305 /// class \b %Ticks.
306 /// @returns The duration represented by the public fields of this class.
307 //==============================================================================================
308 Ticks::Duration ToTicksDuration()
309 {
310 return Ticks::Duration::FromNanoseconds( ToNanoSeconds() );
311 }
312
313 //==============================================================================================
314 /// Sets the public fields to represent the given duration value.
315 /// The state of the object will hereafter be the same as it was when constructed with the same
316 /// parameter.
317 /// @param nanos The duration to use for setting the public fields.
318 //==============================================================================================
319 ALIB_API void FromNanoSeconds( int64_t nanos );
320
321 //==============================================================================================
322 /// Takes the current values of the public fields and returns the duration.
323 /// @returns The duration represented by the public fields of this class in nanoseconds.
324 //==============================================================================================
325 ALIB_API int64_t ToNanoSeconds();
326 //==============================================================================================
327 /// Sets all public values to 0.
328 //==============================================================================================
329 ALIB_API void Clear();
330};
331
332
333
334//==================================================================================================
335/// Represents a date in the systems calendar without the provision of a clock time.
336/// This class internally uses types \alib{time;DateTime} and \alib{lang::system;CalendarDateTime} to
337/// perform operators <c>+</c>, <c>-</c>, <c>+=</c> and <c>-=</c>, but is much more efficient with
338/// in- and decrement operators <c>++</c> and <c>--</c>. Furthermore it uses only 32-bits of storage.
339///
340/// Besides storing clock-time agnostic date values, the type is useful to securely iterate over
341/// dates, because there is no risk of false comparisons due to mixed time-zone and daylight
342/// saving properties and in general due to arbitrarily set clock times.
343///
344/// Another small difference is that field \alib{lang::system::CalendarDate;DayOfWeek} is always kept in a
345/// reliable (correct) state, which is not the case with field
346/// \alib{lang::system;CalendarDateTime::DayOfWeek}.
347///
348/// Internally, the values are stored a 32-bit storage word using the following scheme
349/// - bits 1-3 encode the day of week (from 0 (= Sunday) to 6 (= Saturday)
350/// - bits 4-8 encode the calendar day (1..31)
351/// - bits 9-12 encode the calendar month (1..12)
352/// - bits 13-32 encode the calendar year
353/// consequently, for the calendar year 20 bits are available, which evaluates to a range of
354/// \b 1,048,576 years.
355/// For simplicity and speed, the values are \b not defined in accordance to class
356/// \alib{lang::system;CalendarDateTime}, where a value of \c 0 represents year \b 1900.
357/// This class just stores the year value as is and does not allow negative values.
358/// As a result, this class is capable of storing values between <b>1/1/0000</b> and
359/// <b>12/31/1,048,576</b>.
360//==================================================================================================
362{
363 protected:
364 uint32_t stamp; ///< Encoded date value.
365
366 // #############################################################################################
367 // Conversion to time platform/language specific values
368 // #############################################################################################
369 public:
370 /// Default constructor leaving this object uninitialized (random value). **************
371 CalendarDate() = default;
372
373 /// Trivial default copy constructor. ***************************************************
374 CalendarDate( const CalendarDate& ) noexcept = default;
375
376 /// Trivial default move constructor. ***************************************************
377 CalendarDate( CalendarDate&& ) noexcept = default;
378
379 /// Trivial default copy assign operator.
380 /// @return A reference to \c this. ***************************************************
381 CalendarDate& operator=( const CalendarDate& ) noexcept = default;
382
383 /// Trivial default move assign operator.
384 /// @return A reference to \c this. ***************************************************
385 CalendarDate& operator=( CalendarDate&& ) noexcept = default;
386
387 /// Trivial default destructor. ***************************************************
388 ~CalendarDate() noexcept = default;
389
390 //==========================================================================================
391 /// Constructor taking the date as separated values.
392 /// @param year The year to use. Must be between 0 and 1,048,575
393 /// @param month The month to use. Must be between 1 and 12
394 /// @param day The day to use. Must be between 1 and 31
395 /// @param dayOfWeek The day of week that results from the previous values.
396 /// Defaults to \c -1 which instructs this constructor to retrieve that
397 /// correct value.<br>
398 /// If given, values must be between 0 (Sunday) and 6 (Saturday).
399 /// In debug compilations an assertion will be raised if the
400 /// value is out of range or inconsistent.
401 //==========================================================================================
402 CalendarDate(int year, int month, int day, int dayOfWeek= -1)
403 {
404 Set( year, month, day, dayOfWeek );
405 }
406
407 //==========================================================================================
408 /// Constructor creating a date that represents "today".
409 /// @param timezone Determines whether the local time zone should be used or UTC.
410 //==========================================================================================
411 explicit
413 {
415 }
416
417 //==========================================================================================
418 /// Constructor taking a \b DateTime value.
419 /// @param calendarDateTime The value to take the date from.
420 //==========================================================================================
421 ALIB_API explicit
422 CalendarDate( const CalendarDateTime& calendarDateTime )
423 {
424 Set( calendarDateTime.Year
425 ,calendarDateTime.Month
426 ,calendarDateTime.Day
427 ,calendarDateTime.DayOfWeek );
428 }
429
430 //==========================================================================================
431 /// Constructor taking a \b DateTime value.
432 /// @param dateTime The value to take the date from.
433 /// @param timezone Determines whether the local time zone should be used or UTC.
434 //==========================================================================================
435 CalendarDate( const DateTime& dateTime, lang::Timezone timezone )
436 {
437 Set( dateTime, timezone);
438 }
439
440
441 //==========================================================================================
442 /// Sets this class to the given values.
443 /// @param year The year to use. Must be between 0 and 1,048,575
444 /// @param month The month to use. Must be between 1 and 12
445 /// @param day The day to use. Must be between 1 and 31
446 /// @param dayOfWeek The day of week that results from the previous values.
447 /// Defaults to \c -1 which instructs this constructor to retrieve that
448 /// correct value.<br>
449 /// If given, values must be between 0 (Sunday) and 6 (Saturday).
450 /// In debug compilations an assertion will be raised if the
451 /// value is out of range or inconsistent.
452 //==========================================================================================
454 void Set( int year, int month, int day, int dayOfWeek= -1);
455
456 //==========================================================================================
457 /// Sets this class to the date represented by the given \b DateTime instance.
458 /// @param dateTime The value to take the date from.
459 /// @param timezone Determines whether the local time zone applies to \p dateTime or
460 /// whether it refers to UTC.
461 //==========================================================================================
463 void Set( const DateTime& dateTime, lang::Timezone timezone );
464
465 //==========================================================================================
466 /// Creates a \b DateTime object from this calendar date.
467 /// \attention
468 /// The resolution and possible time range of class \b %DateTime is platform-dependent.
469 /// This method must not be used if inconsistent values are stored.
470 ///
471 /// @param timezone Denote if the time that is calculated should be local or UTC.
472 /// Defaults to \c TimeZone::Local.
473 /// @param hour The hour of day (0..23) that the value returned should represent.
474 /// Defaults to noon time (\c 12).
475 /// @param minute The minute of the hour (0..59) that the value returned should represent.
476 /// Defaults to \c 0.
477 /// @param second The second of the minute (0..59) that the value returned should
478 /// represent. Defaults to \c 0.
479 /// @returns The point in time represented by this class and the given clock values.
480 //==========================================================================================
483 int hour= 12, int minute= 0, int second= 0 ) const;
484
485 //==========================================================================================
486 /// Returns a date and time value, by adding 12 o'clock noon time.
487 /// @return A corresponding \b DateTime value.
488 //==========================================================================================
491
492 //-------------------------- Year(), Month(), Day(), DayOfWeek() ------------------------
493 /// Extracts the day of month from this date as a value between \c 1 and \c 31.
494 /// @return The calendar day of month.
495 int Year() const { return int( stamp >> 12 ); }
496
497 /// Extracts the month from this date as a value between \c 1 and \c 12.
498 /// @return The calendar day of month.
499 int Month() const { return int( (stamp >> 8) & 15 ); }
500
501 /// Extracts the day of month from this date as a value between \c 1 and \c 31.
502 /// @return The calendar day of month.
503 int Day() const { return int( (stamp >> 3) & 31 ); }
504
505 /// Extracts the day of week from this date as a value between \c 0 (representing sunday)
506 /// and \c 6 (representing Saturday) in accordance with field
507 /// \alib{lang::system;CalendarDateTime::DayOfWeek}.
508 /// @return The calendar day of month.
509 int DayOfWeek() const { return int( stamp & 7 ); }
510
511 //--------------------------- +/- and ++/--/+=/-= operators ----------------------------
512
513 //==========================================================================================
514 /// Adds the given number of days to this date.
515 /// @param daysToAdd The days to add. May be negative for subtraction.
516 /// @return A copy of this object after modification.
517 //==========================================================================================
519 CalendarDate operator+ ( int daysToAdd ) const;
520
521 //==========================================================================================
522 /// Subtracts the given number of days to this date.
523 /// @param daysToSubtract The days to add. May be negative for additions.
524 /// @return A copy of this object after modification.
525 //==========================================================================================
526 CalendarDate operator- ( int daysToSubtract ) const
527 {
528 return (*this) + (-daysToSubtract);
529 }
530
531 //==========================================================================================
532 /// Prefix increment operator.
533 /// @return A copy of this object after modification.
534 //==========================================================================================
537
538 //==========================================================================================
539 /// Prefix decrement operator.
540 /// @return A copy of this object after modification.
541 //==========================================================================================
544
545 //==========================================================================================
546 /// Postfix increment operator.
547 /// @return A copy of this object before its modification.
548 //==========================================================================================
550 {
551 auto tmp = *this;
552 ++(*this);
553 return tmp;
554 }
555
556 //==========================================================================================
557 /// Postfix decrement operator.
558 /// @return A copy of this object before its modification.
559 //==========================================================================================
561 {
562 auto tmp = *this;
563 --(*this);
564 return tmp;
565 }
566
567 //==========================================================================================
568 /// Adds the given number of days to this date.
569 /// @param daysToAdd The days to add. May be negative for subtraction.
570 /// @return A copy of this object after modification.
571 //==========================================================================================
572 CalendarDate operator+=( int daysToAdd )
573 {
574 return (*this)= (*this) + daysToAdd;
575 }
576
577 //==========================================================================================
578 /// Subtracts the given number of days to this date.
579 /// @param daysToSubtract The days to add. May be negative for additons.
580 /// @return A copy of this object after modification.
581 //==========================================================================================
582 CalendarDate operator-=( int daysToSubtract )
583 {
584 return (*this)+= (- daysToSubtract);
585 }
586
587
588 //------------------------------------ Comparison ------------------------------------
589 //==========================================================================================
590 /// Equal to operator.
591 /// @param other The date stamp to compare.
592 /// @return The result of the comparison.
593 //==========================================================================================
594 bool operator==( const CalendarDate& other ) const
595 {
596 return stamp == other.stamp;
597 }
598
599 //==========================================================================================
600 /// Not equal to operator.
601 /// @param other The date stamp to compare.
602 /// @return The result of the comparison.
603 //==========================================================================================
604 bool operator!=( const CalendarDate& other ) const
605 {
606 return stamp != other.stamp;
607 }
608
609 //==========================================================================================
610 /// Less than operator.
611 /// @param other The date stamp to compare.
612 /// @return A reference to this object.
613 //==========================================================================================
614 bool operator<( const CalendarDate& other ) const
615 {
616 return stamp < other.stamp;
617 }
618
619 //==========================================================================================
620 /// Less than or equal to operator.
621 /// @param other The date stamp to compare.
622 /// @return The result of the comparison.
623 //==========================================================================================
624 bool operator<=( const CalendarDate& other ) const
625 {
626 return stamp <= other.stamp;
627 }
628
629 //==========================================================================================
630 /// Greater than operator.
631 /// @param other The date stamp to compare.
632 /// @return The result of the comparison.
633 //==========================================================================================
634 bool operator>( const CalendarDate& other ) const
635 {
636 return stamp > other.stamp;
637 }
638
639 //==========================================================================================
640 /// Greater than or equal to operator.
641 /// @param other The date stamp to compare.
642 /// @return The result of the comparison.
643 //==========================================================================================
644 bool operator>=( const CalendarDate& other ) const
645 {
646 return stamp >= other.stamp;
647 }
648}; // class CalendarDate
649
650//==================================================================================================
651/// Implementation of \alib{lang::format;FFormat} for boxable type \alib{time;DateTime}.<br>
652/// Writes the content of \p{box} (which is of type \b %DateTime) to the given \b %AString
653/// object \p{target} using a local instance of class \alib{lang::system;CalendarDateTime} and its method
654/// \alib{lang::system;CalendarDateTime::Format}.
655///
656/// If parameter \p{formatSpec} is empty, a default format string defined by string resource
657/// of key \b "FMTDT" is used.
658///
659/// \note
660/// This interface implementation is only available if modules \alib_basecamp and \alib_time
661/// are included in the library distribution.
662///
663/// @param self The box that the function was invoked on.
664/// @param formatSpec The specification of the format.
665/// @param nf A copy of the number format of the formatter (allowed to be modified).
666/// @param target The AString object receiving the formatted string.
667//==================================================================================================
668ALIB_API void
669FFormat_DateTime( const Box & self, const String & formatSpec, NumberFormat& nf, AString& target );
670
671
672
673} namespace strings {
674
675
676#if DOXYGEN
677namespace APPENDABLES { // Documentation fake namespace
678#endif
679/// Specialization of functor \alib{strings;T_Append} for type
680/// \alib{time;TimePointBase::Duration;DateTime::Duration}.
681template<typename TChar, typename TAllocator> struct T_Append<time::DateTime::Duration ,TChar,TAllocator>
682{
683 //==============================================================================================
684 /// Appends a human-readable string representation of objects of templated inner type
685 /// \alib{time;TimePointBase::Duration} of type \alib{time;DateTime}.
686 ///
687 /// \see
688 /// For details of the conversion, see
689 /// \ref anchor_T_Append_TimePointBase_Duration "documentation of sibling method"
690 /// for type \b %Ticks, which shares this method's implementation.
691 ///
692 /// @param target The \b AString that \b Append was invoked on.
693 /// @param duration The duration to append.
694 //==============================================================================================
695 ALIB_API void operator()( TAString<TChar,TAllocator>& target, const time::DateTime::Duration duration );
696};
697
698/// Specialization of functor \alib{strings;T_Append} for type
699/// \alib{time;TimePointBase::Duration;Ticks::Duration}.
700template<typename TChar, typename TAllocator> struct T_Append<time::Ticks::Duration ,TChar,TAllocator>
701{
702 //==============================================================================================
703 /// \anchor anchor_T_Append_TimePointBase_Duration
704 /// Appends a human-readable string representation of objects of templated inner type
705 /// \alib{time;TimePointBase::Duration} of type \alib{time;Ticks}.
706 ///
707 /// Depending on the length of the duration, a different human-readable time unit or combination
708 /// of it is used. The following rules are checked from top to bottom:
709 /// - If zero, resource string \b "TS_ZERO" is written.
710 /// - If negative, a minus sign <c>'-'</c> is written and the value is negated.
711 /// - If greater than 10 days, writes the number of days as floating point number.
712 /// - If between 1 and 10 days, writes the integral number of days and the additional hours as
713 /// floating point number.
714 /// - If greater than an hour, writes the integral number of hours and integral minutes.
715 /// - If greater than a minute, writes the integral number of minutes and integral seconds.
716 /// - If greater than a second, writes the number of seconds as floating point number.
717 /// - If greater than a millisecond, writes the number of milliseconds as floating point number.
718 /// - If greater than a microsecond, writes the number of microseconds as floating point number.
719 /// - If greater than a nanosecond, writes the number of nanoseconds as floating point number.
720 ///
721 /// All floating point numbers are written with two digits fractional precision.<br>
722 /// The unit symbols are read from the \ref alib_basecamp_resources "resources" of module class
723 /// \alib{lang::basecamp;BaseCamp}. The list is given with resource name <b>UNITS</b>.
724 ///
725 /// @param target The \b AString that \b Append was invoked on.
726 /// @param duration The duration to append.
727 //==============================================================================================
728 void operator()( TAString<TChar,TAllocator>& target, const time::Ticks::Duration duration );
729};
730
734
735#if DOXYGEN
736} // APPENDABLES documentation fake namespace
737#endif
738
739
740} // namespace alib[:: lang::system]
741
742/// Type alias in namespace \b alib.
744
745/// Type alias in namespace \b alib.
747
748/// Type alias in namespace \b alib.
750
751} // namespace [alib]
752
753#endif // HPP_ALIB_LANG_SYSTEM_CALENDAR
754
int Minute
The calendar minute (0..59).
Definition calendar.hpp:63
int Year
The calendar year (e.g., 2022).
Definition calendar.hpp:51
int Month
The calendar month (1..12).
Definition calendar.hpp:54
CalendarDateTime(Initialization init=Initialization::Default)
Definition calendar.hpp:82
ALIB_API void Set(const DateTime &timeStamp, lang::Timezone timezone=lang::Timezone::Local)
Definition calendar.cpp:40
CalendarDateTime(const DateTime &timeStamp, lang::Timezone timezone=lang::Timezone::Local)
Definition calendar.hpp:94
int Day
The calendar day (1..31).
Definition calendar.hpp:57
int Hour
The calendar hour (0..23).
Definition calendar.hpp:60
ALIB_API void Clear()
Sets all public values to 0.
Definition calendar.cpp:28
CalendarDateTime(int year, int month=1, int day=1, int hour=0, int minute=0, int second=0, int millisecond=0)
Definition calendar.hpp:109
int Millisecond
The calendar millisecond (0..999).
Definition calendar.hpp:69
int Second
The calendar second (0..59).
Definition calendar.hpp:66
bool operator<=(const CalendarDate &other) const
Definition calendar.hpp:624
CalendarDate operator-=(int daysToSubtract)
Definition calendar.hpp:582
bool operator==(const CalendarDate &other) const
Definition calendar.hpp:594
CalendarDate operator-(int daysToSubtract) const
Definition calendar.hpp:526
bool operator!=(const CalendarDate &other) const
Definition calendar.hpp:604
ALIB_API CalendarDate operator--()
Definition calendar.cpp:262
ALIB_API CalendarDate operator+(int daysToAdd) const
Definition calendar.cpp:221
ALIB_API CalendarDate(const CalendarDateTime &calendarDateTime)
Definition calendar.hpp:422
bool operator>(const CalendarDate &other) const
Definition calendar.hpp:634
CalendarDate operator+=(int daysToAdd)
Definition calendar.hpp:572
CalendarDate()=default
Default constructor leaving this object uninitialized (random value). **************.
bool operator>=(const CalendarDate &other) const
Definition calendar.hpp:644
bool operator<(const CalendarDate &other) const
Definition calendar.hpp:614
CalendarDate(CalendarDate &&) noexcept=default
Trivial default move constructor. ***************************************************.
uint32_t stamp
Encoded date value.
Definition calendar.hpp:364
CalendarDate(lang::Timezone timezone)
Definition calendar.hpp:412
ALIB_API CalendarDate operator++()
Definition calendar.cpp:229
CalendarDate(const DateTime &dateTime, lang::Timezone timezone)
Definition calendar.hpp:435
ALIB_API void Set(int year, int month, int day, int dayOfWeek=-1)
Definition calendar.cpp:188
CalendarDate(const CalendarDate &) noexcept=default
Trivial default copy constructor. ***************************************************.
ALIB_API CalendarDateTime ToCalendarDateTime() const
int Nanoseconds
The number of nanoseconds (not the total, hence 0-999) within the duration.
Definition calendar.hpp:227
CalendarDuration(lang::Initialization init=Initialization::Default)
Definition calendar.hpp:235
CalendarDuration(DateTime::Duration duration)
Definition calendar.hpp:256
int Milliseconds
The number of milliseconds (not the total, hence 0-999) within the duration.
Definition calendar.hpp:221
int Seconds
The number of seconds (not the total, hence 0-59) within the duration.
Definition calendar.hpp:218
int Microseconds
The number of microseconds (not the total, hence 0-999) within the duration.
Definition calendar.hpp:224
int Days
The number of days within the duration.
Definition calendar.hpp:209
DateTime::Duration ToDateTimeDuration()
Definition calendar.hpp:298
void FromDuration(Ticks::Duration duration)
Definition calendar.hpp:288
int Hours
The number of hours (not the total, hence 0-23) within the duration.
Definition calendar.hpp:212
ALIB_API void FromNanoSeconds(int64_t nanos)
Definition calendar.cpp:154
int Minutes
The number of minutes (not the total, hence 0-59) within the duration.
Definition calendar.hpp:215
ALIB_API void Clear()
Sets all public values to 0.
Definition calendar.cpp:136
CalendarDuration(Ticks::Duration duration)
Definition calendar.hpp:266
void FromDuration(DateTime::Duration duration)
Definition calendar.hpp:277
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:223
#define ALIB_API
Definition alib.hpp:639
ALIB_API void FFormat_DateTime(const Box &self, const String &formatSpec, NumberFormat &nf, AString &target)
Initialization
Used for example with constructors that allow to suppress initialization of members.
Timezone
Denotes whether a time value represents local time or UTC.
@ Local
Denotes local time.
@ Keep
Chooses not no clear existing data.
@ Get
Denotes to search data.
Definition alib.cpp:69
strings::TFormat< character > Format
Type alias in namespace alib.
time::DateTime DateTime
Type alias in namespace alib.
Definition datetime.hpp:228
ALIB_API void operator()(TAString< TChar, TAllocator > &target, const time::DateTime::Duration duration)
void operator()(TAString< TChar, TAllocator > &target, const time::Ticks::Duration duration)
void operator()(TAString< TChar > &target, const TAppendable &src)