MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
mtcore::calendars::CalDate< Calendar > Struct Template Reference

Represents a date without a time component. More...

#include <core.hpp>

Inheritance diagram for mtcore::calendars::CalDate< Calendar >:
Collaboration diagram for mtcore::calendars::CalDate< Calendar >:

Public Types

using CalendarSystem = Calendar
 

Public Member Functions

 CalDate ()=default
 
 CalDate (const CalDate &)=default
 
 CalDate (CalDate &&)=default
 
CalDateoperator= (const CalDate &)=default
 
CalDateoperator= (CalDate &&)=default
 
 CalDate (const Calendar &c)
 
template<typename... Args>
constexpr CalDateinit (Args... args)
 
template<IsDayCalendarSystem Other>
constexpr operator CalDate< Other > () const
 
template<IsDayCalendarSystem Other>
constexpr auto operator<=> (const CalDate< Other > &o) const
 Compares dates between two different calendar systems.
 
template<IsDayCalendarSystem Other>
constexpr auto operator== (const CalDate< Other > &o) const -> bool
 
template<IsDayCalendarSystem Other>
constexpr auto operator!= (const CalDate< Other > &o) const -> bool
 
template<IsDayCalendarSystem Other>
constexpr auto operator<= (const CalDate< Other > &o) const -> bool
 
template<IsDayCalendarSystem Other>
constexpr auto operator>= (const CalDate< Other > &o) const -> bool
 
template<IsDayCalendarSystem Other>
constexpr auto operator< (const CalDate< Other > &o) const -> bool
 
template<IsDayCalendarSystem Other>
constexpr auto operator> (const CalDate< Other > &o) const -> bool
 
constexpr CalDate nearest_valid () const
 Moves the date to the nearest valid date.
 
constexpr bool is_valid () const
 Checks that a date is valid.
 
constexpr DayOfWeek day_of_week () const
 Gets the day of week for a calendar.
 
constexpr CalDate add_days (const i32 days) const
 Adds days to a date.
 
constexpr CalDate sub_days (const i32 days) const
 Subtracts days from a date.
 
template<IsDayCalendarSystem Other>
constexpr i32 day_difference (const CalDate< Other > &other) const
 Gets the difference in days between dates.
 
constexpr CalDate nth_week_day (const i32 n, const DayOfWeek k) const
 Gets the nth day of week.
 
constexpr CalDate day_of_week_before (const DayOfWeek k) const
 Gets the day of week before current date.
 
constexpr CalDate day_of_week_after (const DayOfWeek k) const
 Gets the day of week after the current date.
 
constexpr CalDate day_of_week_nearest (const DayOfWeek k) const
 Gets the day of week nearest to the current date.
 
constexpr CalDate day_of_week_on_or_before (const DayOfWeek k) const
 Gets the day of week on or before the current date.
 
constexpr CalDate day_of_week_on_or_after (const DayOfWeek k) const
 Gets the day of week on or after the current date.
 
constexpr CalDate first_week_day (const DayOfWeek k) const
 Gets the first week day in a month (assuming current date is the start of the month)
 
constexpr CalDate last_week_day (const DayOfWeek k) const
 Gets the last week day in a month (assuming current date is the end of the month)
 
template<IsDayCalendarSystem Other>
auto positions_in_range (Allocator &alloc, const CalDate< Other > &end, i32 pthMoment, i32 cDayCycle, i32 delta) const -> Result< ArrayList< CalDate >, AllocationError >
 Return the cyclic positions in the range of the current date to the end date (exclusive) Used to collect all occurrences of events (e.g.
 
i32 day_of_m_cycle (i32 m, i32 offset) const
 Gets which day the current date occurs in an m-length ("month") cycle.
 
auto kth_day_of_m_cycle_on_or_before (i32 k, i32 m, i32 offset) const noexcept -> CalDate
 Finds the kth day of the m-cycle that occurs on or before the current date.
 
auto kth_day_of_m_cycle_before (i32 k, i32 m, i32 offset) const noexcept -> CalDate
 Finds the kth day of the m-cycle that occurs before the current date.
 
auto kth_day_of_m_cycle_on_or_after (i32 k, i32 m, i32 offset) const noexcept -> CalDate
 Finds the kth day of the m-cycle that occurs on or after the current date.
 
auto kth_day_of_m_cycle_after (i32 k, i32 m, i32 offset) const noexcept -> CalDate
 Finds the kth day of the m-cycle that occurs after the current date.
 
auto kth_day_of_m_cycle_nearest (i32 k, i32 m, i32 offset) const noexcept -> CalDate
 Finds the kth day of the m-cycle that occurs nearest the current date.
 

Static Public Member Functions

template<typename... Args>
static constexpr CalDate make (Args... args)
 

Public Attributes

Calendar cal
 

Detailed Description

template<IsDayCalendarSystem Calendar>
struct mtcore::calendars::CalDate< Calendar >

Represents a date without a time component.

Template Parameters
CalendarCalendar system used for date

Definition at line 116 of file calendars/mtcore_calendars/core.hpp.

Member Typedef Documentation

◆ CalendarSystem

template<IsDayCalendarSystem Calendar>
using mtcore::calendars::CalDate< Calendar >::CalendarSystem = Calendar

Definition at line 117 of file calendars/mtcore_calendars/core.hpp.

Constructor & Destructor Documentation

◆ CalDate() [1/4]

template<IsDayCalendarSystem Calendar>
mtcore::calendars::CalDate< Calendar >::CalDate ( )
default

◆ CalDate() [2/4]

template<IsDayCalendarSystem Calendar>
mtcore::calendars::CalDate< Calendar >::CalDate ( const CalDate< Calendar > & )
default

◆ CalDate() [3/4]

template<IsDayCalendarSystem Calendar>
mtcore::calendars::CalDate< Calendar >::CalDate ( CalDate< Calendar > && )
default

◆ CalDate() [4/4]

template<IsDayCalendarSystem Calendar>
mtcore::calendars::CalDate< Calendar >::CalDate ( const Calendar & c)
inline

Definition at line 125 of file calendars/mtcore_calendars/core.hpp.

Member Function Documentation

◆ add_days()

template<IsDayCalendarSystem Calendar>
CalDate mtcore::calendars::CalDate< Calendar >::add_days ( const i32 days) const
inlinenodiscardconstexpr

Adds days to a date.

Definition at line 205 of file calendars/mtcore_calendars/core.hpp.

205 {
206 return {Calendar::from_fixed(cal.to_fixed().add_days(days))};
207 }

◆ day_difference()

template<IsDayCalendarSystem Calendar>
template<IsDayCalendarSystem Other>
i32 mtcore::calendars::CalDate< Calendar >::day_difference ( const CalDate< Other > & other) const
inlinenodiscardconstexpr

Gets the difference in days between dates.

Definition at line 216 of file calendars/mtcore_calendars/core.hpp.

216 {
217 return cal.to_fixed().day_difference(other.cal.to_fixed());
218 }

◆ day_of_m_cycle()

template<IsDayCalendarSystem Calendar>
i32 mtcore::calendars::CalDate< Calendar >::day_of_m_cycle ( i32 m,
i32 offset ) const
inlinenodiscard

Gets which day the current date occurs in an m-length ("month") cycle.

Parameters
mLength of cycle
offsetOffset for start of cycle

Definition at line 305 of file calendars/mtcore_calendars/core.hpp.

305{ return cal.to_fixed().day_of_m_cycle(m, offset); }

◆ day_of_week()

template<IsDayCalendarSystem Calendar>
DayOfWeek mtcore::calendars::CalDate< Calendar >::day_of_week ( ) const
inlinenodiscardconstexpr

Gets the day of week for a calendar.

Definition at line 202 of file calendars/mtcore_calendars/core.hpp.

202{ return cal.to_fixed().day_of_week(); }

◆ day_of_week_after()

template<IsDayCalendarSystem Calendar>
CalDate mtcore::calendars::CalDate< Calendar >::day_of_week_after ( const DayOfWeek k) const
inlinenodiscardconstexpr

Gets the day of week after the current date.

Definition at line 231 of file calendars/mtcore_calendars/core.hpp.

231 {
232 return {Calendar::from_fixed(cal.to_fixed().day_of_week_after(k))};
233 }

◆ day_of_week_before()

template<IsDayCalendarSystem Calendar>
CalDate mtcore::calendars::CalDate< Calendar >::day_of_week_before ( const DayOfWeek k) const
inlinenodiscardconstexpr

Gets the day of week before current date.

Definition at line 226 of file calendars/mtcore_calendars/core.hpp.

226 {
227 return {Calendar::from_fixed(cal.to_fixed().day_of_week_before(k))};
228 }

◆ day_of_week_nearest()

template<IsDayCalendarSystem Calendar>
CalDate mtcore::calendars::CalDate< Calendar >::day_of_week_nearest ( const DayOfWeek k) const
inlinenodiscardconstexpr

Gets the day of week nearest to the current date.

Definition at line 236 of file calendars/mtcore_calendars/core.hpp.

236 {
237 return {Calendar::from_fixed(cal.to_fixed().day_of_week_nearest(k))};
238 }

◆ day_of_week_on_or_after()

template<IsDayCalendarSystem Calendar>
CalDate mtcore::calendars::CalDate< Calendar >::day_of_week_on_or_after ( const DayOfWeek k) const
inlinenodiscardconstexpr

Gets the day of week on or after the current date.

Definition at line 246 of file calendars/mtcore_calendars/core.hpp.

246 {
247 return {Calendar::from_fixed(cal.to_fixed().day_of_week_on_or_after(k))};
248 }

◆ day_of_week_on_or_before()

template<IsDayCalendarSystem Calendar>
CalDate mtcore::calendars::CalDate< Calendar >::day_of_week_on_or_before ( const DayOfWeek k) const
inlinenodiscardconstexpr

Gets the day of week on or before the current date.

Definition at line 241 of file calendars/mtcore_calendars/core.hpp.

241 {
242 return {Calendar::from_fixed(cal.to_fixed().day_of_week_on_or_before(k))};
243 }

◆ first_week_day()

template<IsDayCalendarSystem Calendar>
CalDate mtcore::calendars::CalDate< Calendar >::first_week_day ( const DayOfWeek k) const
inlinenodiscardconstexpr

Gets the first week day in a month (assuming current date is the start of the month)

Definition at line 251 of file calendars/mtcore_calendars/core.hpp.

251 {
252 return {Calendar::from_fixed(cal.to_fixed().first_week_day(k))};
253 }

◆ init()

template<IsDayCalendarSystem Calendar>
template<typename... Args>
CalDate & mtcore::calendars::CalDate< Calendar >::init ( Args... args)
inlineconstexpr

Definition at line 128 of file calendars/mtcore_calendars/core.hpp.

128 {
129 if constexpr (is_initable<Calendar, Args...>) {
130 cal.init(args...);
131 }
132 else {
133 cal = Calendar{args...};
134 }
135 return *this;
136 }
Here is the caller graph for this function:

◆ is_valid()

template<IsDayCalendarSystem Calendar>
bool mtcore::calendars::CalDate< Calendar >::is_valid ( ) const
inlinenodiscardconstexpr

Checks that a date is valid.

Definition at line 199 of file calendars/mtcore_calendars/core.hpp.

199{ return *this == nearest_valid(); }
constexpr CalDate nearest_valid() const
Moves the date to the nearest valid date.

◆ kth_day_of_m_cycle_after()

template<IsDayCalendarSystem Calendar>
auto mtcore::calendars::CalDate< Calendar >::kth_day_of_m_cycle_after ( i32 k,
i32 m,
i32 offset ) const -> CalDate
inlinenodiscardnoexcept

Finds the kth day of the m-cycle that occurs after the current date.

Parameters
kThe kth day of the m-cycle
mThe number of days in the m-cycle
offsetThe offset of the m-cycle
Returns
A date with the result

Definition at line 347 of file calendars/mtcore_calendars/core.hpp.

347 {
348 return {Calendar::from_fixed(cal.to_fixed().kth_day_of_m_cycle_after(k, m, offset))};
349 }

◆ kth_day_of_m_cycle_before()

template<IsDayCalendarSystem Calendar>
auto mtcore::calendars::CalDate< Calendar >::kth_day_of_m_cycle_before ( i32 k,
i32 m,
i32 offset ) const -> CalDate
inlinenodiscardnoexcept

Finds the kth day of the m-cycle that occurs before the current date.

Parameters
kThe kth day of the m-cycle
mThe number of days in the m-cycle
offsetThe offset of the m-cycle
Returns
A date with the result

Definition at line 325 of file calendars/mtcore_calendars/core.hpp.

325 {
326 return {Calendar::from_fixed(cal.to_fixed().kth_day_of_m_cycle_before(k, m, offset))};
327 }

◆ kth_day_of_m_cycle_nearest()

template<IsDayCalendarSystem Calendar>
auto mtcore::calendars::CalDate< Calendar >::kth_day_of_m_cycle_nearest ( i32 k,
i32 m,
i32 offset ) const -> CalDate
inlinenodiscardnoexcept

Finds the kth day of the m-cycle that occurs nearest the current date.

Parameters
kThe kth day of the m-cycle
mThe number of days in the m-cycle
offsetThe offset of the m-cycle
Returns
A date with the result

Definition at line 358 of file calendars/mtcore_calendars/core.hpp.

358 {
359 return {Calendar::from_fixed(cal.to_fixed().kth_day_of_m_cycle_nearest(k, m, offset))};
360 }

◆ kth_day_of_m_cycle_on_or_after()

template<IsDayCalendarSystem Calendar>
auto mtcore::calendars::CalDate< Calendar >::kth_day_of_m_cycle_on_or_after ( i32 k,
i32 m,
i32 offset ) const -> CalDate
inlinenodiscardnoexcept

Finds the kth day of the m-cycle that occurs on or after the current date.

Parameters
kThe kth day of the m-cycle
mThe number of days in the m-cycle
offsetThe offset of the m-cycle
Returns
A date with the result

Definition at line 336 of file calendars/mtcore_calendars/core.hpp.

336 {
337 return {Calendar::from_fixed(cal.to_fixed().kth_day_of_m_cycle_on_or_after(k, m, offset))};
338 }

◆ kth_day_of_m_cycle_on_or_before()

template<IsDayCalendarSystem Calendar>
auto mtcore::calendars::CalDate< Calendar >::kth_day_of_m_cycle_on_or_before ( i32 k,
i32 m,
i32 offset ) const -> CalDate
inlinenodiscardnoexcept

Finds the kth day of the m-cycle that occurs on or before the current date.

Parameters
kThe kth day of the m-cycle
mThe number of days in the m-cycle
offsetThe offset of the m-cycle
Returns
A date with the result

Definition at line 314 of file calendars/mtcore_calendars/core.hpp.

314 {
315 return {Calendar::from_fixed(cal.to_fixed().kth_day_of_m_cycle_on_or_before(k, m, offset))};
316 }

◆ last_week_day()

template<IsDayCalendarSystem Calendar>
CalDate mtcore::calendars::CalDate< Calendar >::last_week_day ( const DayOfWeek k) const
inlinenodiscardconstexpr

Gets the last week day in a month (assuming current date is the end of the month)

Definition at line 256 of file calendars/mtcore_calendars/core.hpp.

256 {
257 return {Calendar::from_fixed(cal.to_fixed().last_week_day(k))};
258 }

◆ make()

template<IsDayCalendarSystem Calendar>
template<typename... Args>
static constexpr CalDate mtcore::calendars::CalDate< Calendar >::make ( Args... args)
inlinestaticconstexpr

Definition at line 139 of file calendars/mtcore_calendars/core.hpp.

139 {
140 CalDate res;
141 res.init(args...);
142 return res;
143 }
constexpr CalDate & init(Args... args)

◆ nearest_valid()

template<IsDayCalendarSystem Calendar>
CalDate mtcore::calendars::CalDate< Calendar >::nearest_valid ( ) const
inlinenodiscardconstexpr

Moves the date to the nearest valid date.

Definition at line 196 of file calendars/mtcore_calendars/core.hpp.

196{ return {Calendar::from_fixed(cal.to_fixed())}; }
Here is the caller graph for this function:

◆ nth_week_day()

template<IsDayCalendarSystem Calendar>
CalDate mtcore::calendars::CalDate< Calendar >::nth_week_day ( const i32 n,
const DayOfWeek k ) const
inlinenodiscardconstexpr

Gets the nth day of week.

Definition at line 221 of file calendars/mtcore_calendars/core.hpp.

221 {
222 return {Calendar::from_fixed(cal.to_fixed().nth_week_day(n, k))};
223 }

◆ operator CalDate< Other >()

template<IsDayCalendarSystem Calendar>
template<IsDayCalendarSystem Other>
mtcore::calendars::CalDate< Calendar >::operator CalDate< Other > ( ) const
inlinenodiscardconstexpr

Definition at line 146 of file calendars/mtcore_calendars/core.hpp.

146 {
147 return {Other::from_fixed(cal.to_fixed())};
148 }

◆ operator!=()

template<IsDayCalendarSystem Calendar>
template<IsDayCalendarSystem Other>
auto mtcore::calendars::CalDate< Calendar >::operator!= ( const CalDate< Other > & o) const -> bool
inlinenodiscardconstexpr

Definition at line 170 of file calendars/mtcore_calendars/core.hpp.

170 {
171 auto cmp = *this <=> o;
172 return cmp != decltype(cmp)::equivalent;
173 }

◆ operator<()

template<IsDayCalendarSystem Calendar>
template<IsDayCalendarSystem Other>
auto mtcore::calendars::CalDate< Calendar >::operator< ( const CalDate< Other > & o) const -> bool
inlinenodiscardconstexpr

Definition at line 185 of file calendars/mtcore_calendars/core.hpp.

185 {
186 auto cmp = *this <=> o;
187 return cmp == decltype(cmp)::less;
188 }

◆ operator<=()

template<IsDayCalendarSystem Calendar>
template<IsDayCalendarSystem Other>
auto mtcore::calendars::CalDate< Calendar >::operator<= ( const CalDate< Other > & o) const -> bool
inlinenodiscardconstexpr

Definition at line 175 of file calendars/mtcore_calendars/core.hpp.

175 {
176 auto cmp = *this <=> o;
177 return cmp == decltype(cmp)::equivalent || cmp == decltype(cmp)::less;
178 }

◆ operator<=>()

template<IsDayCalendarSystem Calendar>
template<IsDayCalendarSystem Other>
auto mtcore::calendars::CalDate< Calendar >::operator<=> ( const CalDate< Other > & o) const
inlinenodiscardconstexpr

Compares dates between two different calendar systems.

Template Parameters
OtherCalendar system to compare to
Parameters
oOther date to compare to

Definition at line 156 of file calendars/mtcore_calendars/core.hpp.

156 {
158 return cal <=> o.cal;
159 }
160 else {
161 return cal.to_fixed() <=> o.cal.to_fixed();
162 }
163 }

◆ operator=() [1/2]

template<IsDayCalendarSystem Calendar>
CalDate & mtcore::calendars::CalDate< Calendar >::operator= ( CalDate< Calendar > && )
default

◆ operator=() [2/2]

template<IsDayCalendarSystem Calendar>
CalDate & mtcore::calendars::CalDate< Calendar >::operator= ( const CalDate< Calendar > & )
default

◆ operator==()

template<IsDayCalendarSystem Calendar>
template<IsDayCalendarSystem Other>
auto mtcore::calendars::CalDate< Calendar >::operator== ( const CalDate< Other > & o) const -> bool
inlinenodiscardconstexpr

Definition at line 165 of file calendars/mtcore_calendars/core.hpp.

165 {
166 auto cmp = *this <=> o;
167 return cmp == decltype(cmp)::equivalent;
168 }

◆ operator>()

template<IsDayCalendarSystem Calendar>
template<IsDayCalendarSystem Other>
auto mtcore::calendars::CalDate< Calendar >::operator> ( const CalDate< Other > & o) const -> bool
inlinenodiscardconstexpr

Definition at line 190 of file calendars/mtcore_calendars/core.hpp.

190 {
191 auto cmp = *this <=> o;
192 return cmp == decltype(cmp)::greater;
193 }

◆ operator>=()

template<IsDayCalendarSystem Calendar>
template<IsDayCalendarSystem Other>
auto mtcore::calendars::CalDate< Calendar >::operator>= ( const CalDate< Other > & o) const -> bool
inlinenodiscardconstexpr

Definition at line 180 of file calendars/mtcore_calendars/core.hpp.

180 {
181 auto cmp = *this <=> o;
182 return cmp == decltype(cmp)::equivalent || cmp == decltype(cmp)::greater;
183 }

◆ positions_in_range()

template<IsDayCalendarSystem Calendar>
template<IsDayCalendarSystem Other>
auto mtcore::calendars::CalDate< Calendar >::positions_in_range ( Allocator & alloc,
const CalDate< Other > & end,
i32 pthMoment,
i32 cDayCycle,
i32 delta ) const -> Result<ArrayList<CalDate>, AllocationError>
inlinenodiscard

Return the cyclic positions in the range of the current date to the end date (exclusive) Used to collect all occurrences of events (e.g.

holidays) in an interval of time (e.g. a Gregorian year)

Assumes $0 \le pthMoment \lt cDayCycle$

Parameters
allocAllocator to use
endEnd of the cyclic range
pthMomentStarting pth moment search. First result on or after a given moment of the pth moment (basically the cycle start)
cDayCycleThe number of days in the occurrence day cycle (basically the cycle length)
deltaCongruent modulo of cDayCycle to the position of RdDate{0} in the repeating cycle (basically the cycle modulo offset)
Returns

Definition at line 276 of file calendars/mtcore_calendars/core.hpp.

277 {
279 cal.to_fixed().positions_in_range(alloc, end.cal.to_fixed(), pthMoment, cDayCycle, delta);
280 if (fixedRes.is_error()) {
281 return fixedRes.error();
282 }
283
284 auto fixedDates = fixedRes.value();
285 mtdefer { fixedDates.deinit(alloc); };
287 if (const auto r = res.init(alloc, fixedDates.size()); r.is_error()) {
288 return r.error();
289 }
290
291 auto iter = fixedDates.iter();
292 Fixed cur = {};
293 while (iter.next().copy_if_present(cur)) {
294 ensure(res.push(CalDate{Calendar::from_fixed(cur)}).is_success());
295 }
296
297 return success(res);
298 }
#define ensure(check,...)
Ensures that a check holds true, aborts the program if not true Will print error if the condition is ...
Success< void > success()
Creates a successful void Result object.
Definition result.hpp:398

◆ sub_days()

template<IsDayCalendarSystem Calendar>
CalDate mtcore::calendars::CalDate< Calendar >::sub_days ( const i32 days) const
inlinenodiscardconstexpr

Subtracts days from a date.

Definition at line 210 of file calendars/mtcore_calendars/core.hpp.

210 {
211 return {Calendar::from_fixed(cal.to_fixed().sub_days(days))};
212 }

Member Data Documentation

◆ cal

template<IsDayCalendarSystem Calendar>
Calendar mtcore::calendars::CalDate< Calendar >::cal

Definition at line 118 of file calendars/mtcore_calendars/core.hpp.


The documentation for this struct was generated from the following file: