ORIGINAL
Loading...
Searching...
No Matches
original::time::UTCTime Class Referencefinal

Represents a UTC calendar date and time. More...

#include <zeit.h>

Inheritance diagram for original::time::UTCTime:
Inheritance graph
Collaboration diagram for original::time::UTCTime:
Collaboration graph

Public Member Functions

bool isLeapYear () const
 Checks if this year is a leap year.
 
weekdays weekday () const
 Gets weekday for this date.
 
 UTCTime ()
 Constructs a UTCTime object representing the epoch (1970-01-01 00:00:00 UTC)
 
 UTCTime (integer year, integer month, integer day)
 Constructs a UTCTime object with specified date components (time set to 00:00:00)
 
 UTCTime (integer year, integer month, integer day, integer hour, integer minute, integer second)
 Constructs a UTCTime object with all date and time components.
 
 UTCTime (const point &p)
 Constructs a UTCTime object from a time point.
 
 UTCTime (const UTCTime &other)=default
 Default copy constructor.
 
UTCTimeoperator= (const UTCTime &other)=default
 Default copy assignment.
 
 UTCTime (UTCTime &&other) noexcept
 Move constructor.
 
UTCTimeoperator= (UTCTime &&other) noexcept
 Move assignment.
 
UTCTime date () const
 Returns a new UTCTime object containing only the calendar date.
 
integer value (unit unit) const
 Gets time component value.
 
integer value (calendar calendar) const
 Gets calendar component value.
 
 operator point () const
 Converts to time::point.
 
point toPoint () const
 
integer compareTo (const UTCTime &other) const override
 Compares this UTCTime to another.
 
u_integer toHash () const noexcept override
 Computes hash value for this UTCTime.
 
std::string className () const override
 Gets the class name.
 
std::string toString (bool enter) const override
 Converts UTCTime to string representation (YYYY-MM-DD HH:MM:SS)
 
- Public Member Functions inherited from original::comparable< UTCTime >
virtual integer compareTo (const UTCTime &other) const=0
 Compares the current object with another of the same type.
 
bool operator== (const UTCTime &other) const
 Checks if the current object is equal to another.
 
bool operator!= (const UTCTime &other) const
 Checks if the current object is not equal to another.
 
bool operator< (const UTCTime &other) const
 Checks if the current object is less than another.
 
bool operator> (const UTCTime &other) const
 Checks if the current object is greater than another.
 
bool operator<= (const UTCTime &other) const
 Checks if the current object is less than or equal to another.
 
bool operator>= (const UTCTime &other) const
 Checks if the current object is greater than or equal to another.
 
virtual ~comparable ()=default
 Virtual destructor for proper cleanup of derived objects.
 
- Public Member Functions inherited from original::hashable< UTCTime >
virtual bool equals (const UTCTime &other) const noexcept
 Compares two objects for equality.
 
virtual ~hashable ()=0
 Virtual destructor.
 
- Public Member Functions inherited from original::printable
 operator std::string () const
 Explicit conversion to std::string.
 
 operator const char * () const
 Explicit conversion to C-style string.
 
const char * toCString (bool enter) const
 Direct C-string access with formatting control.
 
template<typename TYPE >
auto formatString (const TYPE &t) -> std::string
 
template<typename TYPE >
auto formatCString (const TYPE &t) -> const char *
 
template<typename TYPE >
auto formatEnum (const TYPE &t) -> std::string
 
template<typename TYPE >
auto formatString (TYPE *const &ptr) -> std::string
 

Static Public Member Functions

static UTCTime now ()
 Gets current UTC time.
 
static integer localZonedOffset ()
 Returns the system's local timezone offset in hours from UTC.
 
static UTCTime localNow ()
 Returns the current local time as UTCTime.
 
static constexpr bool isLeapYear (integer year)
 Checks if year is a leap year.
 
static constexpr integer daysOfMonth (integer year, integer month)
 Gets days in specified month.
 
static constexpr weekdays weekday (integer year, integer month, integer day)
 Calculates weekday for given date.
 
static constexpr bool isValidYMD (integer year, integer month, integer day)
 Checks if year-month-day is valid.
 
static constexpr bool isValidHMS (integer hour, integer minute, integer second)
 Checks if hour-minute-second is valid.
 
static constexpr bool isValid (integer year, integer month, integer day, integer hour, integer minute, integer second)
 Checks if full date-time is valid.
 
- Static Public Member Functions inherited from original::printable
template<typename TYPE >
static std::string formatString (const TYPE &t)
 Universal value-to-string conversion.
 
template<Printable TYPE>
static std::string formatString (const TYPE &t)
 Specialization for printable types.
 
template<EnumType TYPE>
static std::string formatString (const TYPE &t)
 Specialization for enum types.
 
template<typename TYPE >
static std::string formatString (TYPE *const &ptr)
 Pointer-specific formatting.
 
template<typename TYPE >
static const char * formatCString (const TYPE &t)
 C-string cache for temporary usage.
 
template<typename TYPE >
static std::string formatEnum (const TYPE &t)
 Enum formatting utility.
 
template<>
auto formatString (const char &t) -> std::string
 
template<>
auto formatString (const bool &t) -> std::string
 
template<>
auto formatString (const char *const &ptr) -> std::string
 

Public Attributes

friend time
 

Static Public Attributes

static constexpr auto SATURDAY = weekdays::SATURDAY
 Constant for Saturday.
 
static constexpr auto SUNDAY = weekdays::SUNDAY
 Constant for Sunday.
 
static constexpr auto MONDAY = weekdays::MONDAY
 Constant for Monday.
 
static constexpr auto TUESDAY = weekdays::TUESDAY
 Constant for Tuesday.
 
static constexpr auto WEDNESDAY = weekdays::WEDNESDAY
 Constant for Wednesday.
 
static constexpr auto THURSDAY = weekdays::THURSDAY
 Constant for Thursday.
 
static constexpr auto FRIDAY = weekdays::FRIDAY
 Constant for Friday.
 
static constexpr integer DAYS_WEEK = 7
 Days in a week.
 
static constexpr integer MONTHS_YEAR = std::size(DAYS_OF_MONTH)
 Months in a year.
 
static constexpr integer YEARS_CENTURY = 100
 Years in a century.
 
static const UTCTime EPOCH = UTCTime{}
 Epoch time constant (1970-01-01 00:00:00)
 

Friends

UTCTime operator+ (const UTCTime &t, const duration &d)
 Adds duration to UTCTime.
 
UTCTime operator+ (const duration &d, const UTCTime &t)
 Adds duration to UTCTime (Reversed version)
 
UTCTime operator- (const UTCTime &t, const duration &d)
 Subtracts duration from UTCTime.
 
duration operator- (const UTCTime &lhs, const UTCTime &rhs)
 Computes duration between two UTCTimes.
 

Detailed Description

Represents a UTC calendar date and time.

Provides calendar operations including:

  • Leap year detection
  • Days in month calculation
  • Weekday calculation
  • Conversion to/from time points

Constructor & Destructor Documentation

◆ UTCTime() [1/5]

original::time::UTCTime::UTCTime ( )
inlineexplicit

Constructs a UTCTime object representing the epoch (1970-01-01 00:00:00 UTC)

Initializes all time components to zero, representing the Unix epoch.

See also
UTCTime::EPOCH
UTCTime t; // Creates epoch time (1970-01-01 00:00:00)
Represents a UTC calendar date and time.
Definition zeit.h:534

◆ UTCTime() [2/5]

original::time::UTCTime::UTCTime ( integer year,
integer month,
integer day )
inlineexplicit

Constructs a UTCTime object with specified date components (time set to 00:00:00)

Parameters
yearThe year component
monthThe month component (1-12)
dayThe day component (1-31, must be valid for month/year)
Exceptions
valueErrorif any component is invalid or date is impossible
See also
isValidYMD(), daysOfMonth()
UTCTime t(2025, 6, 28); // Creates 2025-06-28 00:00:00

◆ UTCTime() [3/5]

original::time::UTCTime::UTCTime ( integer year,
integer month,
integer day,
integer hour,
integer minute,
integer second )
inlineexplicit

Constructs a UTCTime object with all date and time components.

Parameters
yearThe year component (must be >= 1970)
monthThe month component (1-12)
dayThe day component (1-31, must be valid for month/year)
hourThe hour component (0-23)
minuteThe minute component (0-59)
secondThe second component (0-59)
Exceptions
valueErrorif any component is invalid or datetime is impossible
See also
isValid(), isValidYMD(), isValidHMS()
UTCTime t(2025, 6, 28, 14, 30, 0); // Creates 2025-06-28 14:30:00

◆ UTCTime() [4/5]

original::time::UTCTime::UTCTime ( const point & p)
inlineexplicit

Constructs a UTCTime object from a time point.

Parameters
pThe time point to convert from
Warning
Conversion from time::point to UTCTime may lose precision since UTCTime only stores whole seconds (sub-second components are truncated)
UTCTime t(p); // Creates UTCTime from current time (seconds precision)
Represents a point in time with nanosecond precision.
Definition zeit.h:374
static point now()
Gets current time point.
Definition zeit.h:1352

◆ UTCTime() [5/5]

original::time::UTCTime::UTCTime ( UTCTime && other)
inlinenoexcept

Move constructor.

Parameters
otherUTCTime to move from

Member Function Documentation

◆ className()

std::string original::time::UTCTime::className ( ) const
inlineoverridevirtual

Gets the class name.

Returns
"time::UTCTime"

Reimplemented from original::printable.

◆ compareTo()

original::integer original::time::UTCTime::compareTo ( const UTCTime & other) const
inlineoverride

Compares this UTCTime to another.

Parameters
otherUTCTime to compare with
Returns
Negative if this < other, 0 if equal, positive if this > other

◆ date()

original::time::UTCTime original::time::UTCTime::date ( ) const
inline

Returns a new UTCTime object containing only the calendar date.

Returns
A new UTCTime object with time components cleared (00:00:00).
See also
UTCTime::toString(), UTCTime::now()
UTCTime t(2025, 6, 28, 11, 12, 30);
UTCTime d = t.date();
// d == (time::UTCTime 2025-06-28 00:00:00)
UTCTime date() const
Returns a new UTCTime object containing only the calendar date.
Definition zeit.h:1696

◆ daysOfMonth()

original::integer original::time::UTCTime::daysOfMonth ( integer year,
integer month )
staticconstexpr

Gets days in specified month.

Parameters
yearYear (for leap year calculation)
monthMonth (1-12)
Returns
Number of days in month
Exceptions
valueErrorif month is invalid

◆ isLeapYear() [1/2]

bool original::time::UTCTime::isLeapYear ( ) const
inlinenodiscard

Checks if this year is a leap year.

Returns
true if leap year, false otherwise

◆ isLeapYear() [2/2]

bool original::time::UTCTime::isLeapYear ( integer year)
staticconstexpr

Checks if year is a leap year.

Parameters
yearYear to check
Returns
true if leap year, false otherwise

◆ isValid()

bool original::time::UTCTime::isValid ( integer year,
integer month,
integer day,
integer hour,
integer minute,
integer second )
staticconstexpr

Checks if full date-time is valid.

Parameters
yearYear
monthMonth (1-12)
dayDay (1-31)
hourHour (0-23)
minuteMinute (0-59)
secondSecond (0-59)
Returns
true if valid, false otherwise

◆ isValidHMS()

bool original::time::UTCTime::isValidHMS ( integer hour,
integer minute,
integer second )
staticconstexpr

Checks if hour-minute-second is valid.

Parameters
hourHour (0-23)
minuteMinute (0-59)
secondSecond (0-59)
Returns
true if valid, false otherwise

◆ isValidYMD()

bool original::time::UTCTime::isValidYMD ( integer year,
integer month,
integer day )
staticconstexpr

Checks if year-month-day is valid.

Parameters
yearYear
monthMonth (1-12)
dayDay (1-31)
Returns
true if valid, false otherwise

◆ localNow()

original::time::UTCTime original::time::UTCTime::localNow ( )
inlinestatic

Returns the current local time as UTCTime.

Returns
UTCTime representing local time.
Note
This is computed by adding the local timezone offset to the current UTC time.

◆ localZonedOffset()

original::integer original::time::UTCTime::localZonedOffset ( )
inlinestatic

Returns the system's local timezone offset in hours from UTC.

Returns
Local timezone offset in hours.
Note
This accounts for daylight saving time if applicable.

◆ now()

original::time::UTCTime original::time::UTCTime::now ( )
inlinestatic

Gets current UTC time.

Returns
Current UTC time

◆ operator point()

original::time::UTCTime::operator point ( ) const
inlineexplicit

Converts to time::point.

Returns
Time point representing this UTC time
Warning
When converting back to time::point, the time point will only have second-level precision (sub-second components will be zero)

◆ operator=()

original::time::UTCTime & original::time::UTCTime::operator= ( UTCTime && other)
inlinenoexcept

Move assignment.

Parameters
otherUTCTime to move from
Returns
Reference to this UTCTime

◆ toHash()

original::u_integer original::time::UTCTime::toHash ( ) const
inlineoverridevirtualnoexcept

Computes hash value for this UTCTime.

Returns
Hash value

Reimplemented from original::hashable< UTCTime >.

◆ toString()

std::string original::time::UTCTime::toString ( bool enter) const
inlineoverridevirtual

Converts UTCTime to string representation (YYYY-MM-DD HH:MM:SS)

Parameters
enterWhether to include newline
Returns
String representation

Reimplemented from original::printable.

◆ value() [1/2]

original::integer original::time::UTCTime::value ( calendar calendar) const
inline

Gets calendar component value.

Parameters
calendarCalendar component to get
Returns
Value of requested component

◆ value() [2/2]

original::integer original::time::UTCTime::value ( unit unit) const
inline

Gets time component value.

Parameters
unitTime unit to get
Returns
Value of requested component

◆ weekday() [1/2]

original::time::UTCTime::weekdays original::time::UTCTime::weekday ( ) const
inlinenodiscard

Gets weekday for this date.

Returns
Weekday

◆ weekday() [2/2]

original::time::UTCTime::weekdays original::time::UTCTime::weekday ( integer year,
integer month,
integer day )
staticconstexpr

Calculates weekday for given date.

Parameters
yearYear
monthMonth (1-12)
dayDay (1-31)
Returns
Weekday for date
Exceptions
valueErrorif date is invalid

Friends And Related Symbol Documentation

◆ operator+ [1/2]

UTCTime operator+ ( const duration & d,
const UTCTime & t )
friend

Adds duration to UTCTime (Reversed version)

Parameters
dDuration to add
tUTCTime
Returns
New UTCTime after addition

◆ operator+ [2/2]

UTCTime operator+ ( const UTCTime & t,
const duration & d )
friend

Adds duration to UTCTime.

Parameters
tUTCTime
dDuration to add
Returns
New UTCTime after addition

◆ operator- [1/2]

duration operator- ( const UTCTime & lhs,
const UTCTime & rhs )
friend

Computes duration between two UTCTimes.

Parameters
lhsLeft operand
rhsRight operand
Returns
Duration between UTCTimes

◆ operator- [2/2]

UTCTime operator- ( const UTCTime & t,
const duration & d )
friend

Subtracts duration from UTCTime.

Parameters
tUTCTime
dDuration to subtract
Returns
New UTCTime after subtraction

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