8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
18 module ALib.Strings.Calendar;
34DOX_MARKER( [CDT_MONTH_NAMES])
41DOX_MARKER( [CDT_MONTH_NAMES])
49DOX_MARKER( [CDT_DAY_NAMES])
54DOX_MARKER( [CDT_DAY_NAMES])
88 #elif defined (__GLIBCXX__) || defined(_LIBCPP_VERSION) || defined(__APPLE__) || defined(__ANDROID_NDK__)
96 localtime_r( &tt, &tm );
99 Year= tm.tm_year + 1900;
102 Month= tm.tm_mon + 1;
108 #pragma message ("Unknown Platform in file: " __FILE__ )
115 #if defined( _WIN32 )
118 st.wYear= (WORD)
Year;
121 st.wMonth= (WORD)
Month;
122 st.wHour= (WORD)
Hour;
123 st.wMinute= (WORD)
Minute;
124 st.wSecond= (WORD)
Second;
129 #elif defined (__GLIBCXX__) || defined(_LIBCPP_VERSION) || defined(__APPLE__) || defined(__ANDROID_NDK__)
131 tm.tm_year=
Year - 1900;
151 #pragma message ("Unknown Platform in file: " __FILE__ )
171#define NanosPerDay INT64_C( 86400000000000 )
172#define NanosPerHour INT64_C( 3600000000000 )
173#define NanosPerMinute INT64_C( 60000000000 )
174#define NanosPerSecond INT64_C( 1000000000 )
175#define NanosPerMillisecond INT64_C( 1000000 )
176#define NanosPerMicrosecond INT64_C( 1000 )
181 decltype(nanos) fract;
182 if ( nanos > NanosPerDay ) {
Days= int( fract= nanos / NanosPerDay ); nanos-= fract * NanosPerDay; }
183 if ( nanos > NanosPerHour ) {
Hours= int( fract= nanos / NanosPerHour ); nanos-= fract * NanosPerHour; }
184 if ( nanos > NanosPerMinute ) {
Minutes= int( fract= nanos / NanosPerMinute ); nanos-= fract * NanosPerMinute; }
185 if ( nanos > NanosPerSecond ) {
Seconds= int( fract= nanos / NanosPerSecond ); nanos-= fract * NanosPerSecond; }
186 if ( nanos > NanosPerMillisecond ) {
Milliseconds= int( fract= nanos / NanosPerMillisecond ); nanos-= fract * NanosPerMillisecond; }
187 if ( nanos > NanosPerMicrosecond ) {
Microseconds= int( fract= nanos / NanosPerMicrosecond ); }
191 return Days * NanosPerDay
192 +
Hours * NanosPerHour
206 | uint32_t( cdt.
Month ) << 8
207 | uint32_t( cdt.
Day ) << 3
211 ALIB_ASSERT_ERROR( year >= 0 && year <= 1048575,
"CAMP",
"CalendarDate: Years must be between 0 and 1,048,575. Given: ", year )
212 ALIB_ASSERT_ERROR( month >= 1 && month <= 12 ,
"CAMP",
"CalendarDate: Months must be between 1 and 12. Given: ", month )
213 ALIB_ASSERT_ERROR( day >= 1 && day <= 31 ,
"CAMP",
"CalendarDate: Days must be between 1 and 31. Given: ", day )
214 ALIB_ASSERT_ERROR( dayOfWeek <= 6 ,
"CAMP",
"CalendarDate: Day of week must be either negative or between 0 and 6. Given: ", dayOfWeek)
226 "Given day of week {} does not correspond to given date. Should be: ",
230 stamp= uint32_t( year ) << 12
231 | uint32_t( month ) << 8
232 | uint32_t( day ) << 3
233 | uint32_t( dayOfWeek ) ;
242 + DateTime::Duration::FromAbsoluteDays( daysToAdd ),
252 if( ( month != 2 && day != 30 )
253 || ( month == 2 && day != 28 ) )
256 && ( day != 29 || month != 2 ) )
261 if( ++month == 13 ) {
280 | ( uint32_t( day-1 ) << 3 )
281 | ( ( (
stamp & 7) + 6 ) % 7 ) ;
301 while (
format.IsNotEmpty() ) {
305 while (
format.ConsumeChar(c) )
323 ALIB_WARNING(
"ALIB",
"Format Error: Missing single Quote" )
324 target <<
"Format Error: Missing closing single quote character <'>" ;
344 target.
_<
NC>(
Hour < 12 ?
" am" :
" pm" );
TAString & InsertChars(TChar c, integer qty)
TAString & _(const TAppendable &src)
int Minute
The calendar minute (0..59).
ALIB_DLL void Set(const DateTime &timeStamp, lang::Timezone timezone=lang::Timezone::Local)
int Second
The calendar second (0..59).
int Day
The calendar day (1..31).
ALIB_DLL AString & Format(Substring format, AString &target, lang::CurrentData targetData=lang::CurrentData::Keep) const
int Hour
The calendar hour (0..23).
static ALIB_DLL String MONTH_NAMES[12]
int Year
The calendar year (e.g., 2022).
ALIB_DLL DateTime Get(lang::Timezone timezone=lang::Timezone::Local) const
ALIB_DLL void Clear()
Sets all public values to 0.
static ALIB_DLL String DAY_NAMES[7]
int Month
The calendar month (1..12).
int Millisecond
The calendar millisecond (0..999).
CalendarDate()=default
Default constructor leaving this object uninitialized (random value).
ALIB_DLL void Set(int year, int month, int day, int dayOfWeek=-1)
ALIB_DLL CalendarDate operator++()
uint32_t stamp
Encoded date value.
ALIB_DLL DateTime Get(lang::Timezone timezone=lang::Timezone::Local, int hour=12, int minute=0, int second=0) const
ALIB_DLL CalendarDate operator+(int daysToAdd) const
ALIB_DLL CalendarDate operator--()
int Seconds
The number of seconds (not the total, hence 0-59) within the duration.
ALIB_DLL void FromNanoSeconds(int64_t nanos)
int Hours
The number of hours (not the total, hence 0-23) within the duration.
int Nanoseconds
The number of nanoseconds (not the total, hence 0-999) within the duration.
int Minutes
The number of minutes (not the total, hence 0-59) within the duration.
int Milliseconds
The number of milliseconds (not the total, hence 0-999) within the duration.
ALIB_DLL void Clear()
Sets all public values to 0.
int Microseconds
The number of microseconds (not the total, hence 0-999) within the duration.
int Days
The number of days within the duration.
ALIB_DLL int64_t ToNanoSeconds()
time_t InEpochSeconds() const
static ALIB_DLL DateTime FromSystemTime(const SYSTEMTIME &systemTime, lang::Timezone timezone=lang::Timezone::Local)
ALIB_DLL SYSTEMTIME ToSystemTime(lang::Timezone timezone=lang::Timezone::Local) const
static DateTime FromEpochSeconds(time_t epochSeconds)
#define ALIB_WARNING(domain,...)
#define ALIB_ASSERT_ERROR(cond, domain,...)
@ Clear
Chooses to clear existing data.
Timezone
Denotes whether a time value represents local time or UTC.
@ UTC
Denotes UTC (coordinated universal time).
strings::TDec< character > Dec
Type alias in namespace alib.
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
time::DateTime DateTime
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
strings::TNumberFormat< character > NumberFormat
Type alias in namespace alib.
strings::util::CalendarDateTime CalendarDateTime
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
characters::character character
Type alias in namespace alib.
strings::TSubstring< character > Substring
Type alias in namespace alib.