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