MUSX Document Model
Loading...
Searching...
No Matches
musx::util::DateTime Struct Reference

Static class to provide utility functions for formatting date and time. More...

#include <DateTimeFormat.h>

Public Types

enum class  DateFormatStyle : int { Short = 0 , Long = 1 , LongAbbreviated = 2 }
 Defines the date format styles supported by formatDate. More...
 

Static Public Member Functions

static std::time_t makeTimeT (int year, int month, int day)
 Creates a std::time_t from integer year, month, and day.
 
static std::string formatDate (std::time_t t, DateFormatStyle style)
 Formats a date according to the current locale on POSIX systems.
 
static std::string formatTime (std::time_t t, bool includeSeconds)
 Formats a time according to the current locale.
 

Detailed Description

Static class to provide utility functions for formatting date and time.

Member Enumeration Documentation

◆ DateFormatStyle

enum class musx::util::DateTime::DateFormatStyle : int
strong

Defines the date format styles supported by formatDate.

Enumerator
Short 

Short date format (e.g., 7/10/25)

Long 

Long date format (e.g., July 10, 2025)

LongAbbreviated 

Long abbreviated date format (e.g., Jul 10, 2025)

Member Function Documentation

◆ formatDate()

static std::string musx::util::DateTime::formatDate ( std::time_t  t,
DateFormatStyle  style 
)
inlinestatic

Formats a date according to the current locale on POSIX systems.

Uses strftime to produce a locale-specific date string.

Parameters
tThe time value to format.
styleThe desired date format style.
Returns
A formatted date string, or an empty string on failure.

◆ formatTime()

static std::string musx::util::DateTime::formatTime ( std::time_t  t,
bool  includeSeconds 
)
inlinestatic

Formats a time according to the current locale.

If includeSeconds is true, uses locale-based full time formatting. If includeSeconds is false, formats as hh:mm, choosing 12h or 24h based on system or locale preference.

Parameters
tThe time value to format.
includeSecondsIf true, includes seconds in the formatted time.
Returns
A formatted time string.

◆ makeTimeT()

static std::time_t musx::util::DateTime::makeTimeT ( int  year,
int  month,
int  day 
)
inlinestatic

Creates a std::time_t from integer year, month, and day.

Parameters
yearFull year (e.g., 2025).
monthMonth of year (1-12).
dayDay of month (1-31).
Returns
std::time_t representing the local time at midnight of that date.