Faker C++
Loading...
Searching...
No Matches
faker::date Namespace Reference

Enumerations

enum class  DateFormat { ISO , Timestamp }
 

Functions

FAKER_CXX_EXPORT std::string anytime (DateFormat dateFormat=DateFormat::ISO)
 Generates a random date between UNIX epoch and 200 years from now.
 
FAKER_CXX_EXPORT std::string pastDate (int years=1, DateFormat dateFormat=DateFormat::ISO)
 Generates a random date in the past.
 
FAKER_CXX_EXPORT std::string futureDate (int years=1, DateFormat dateFormat=DateFormat::ISO)
 Generates a random date in the future.
 
FAKER_CXX_EXPORT std::string recentDate (int days=3, DateFormat dateFormat=DateFormat::ISO)
 Generates a random date in the recent past.
 
FAKER_CXX_EXPORT std::string soonDate (int days=3, DateFormat dateFormat=DateFormat::ISO)
 Generates a random date in the soon future.
 
FAKER_CXX_EXPORT std::string birthdateByAge (int minAge=18, int maxAge=80, DateFormat dateFormat=DateFormat::ISO)
 Generates a random birthdate by age.
 
FAKER_CXX_EXPORT std::string birthdateByYear (int minYear=1920, int maxYear=2000, DateFormat dateFormat=DateFormat::ISO)
 Generates a random birthdate by year.
 
FAKER_CXX_EXPORT std::string_view weekdayName ()
 Returns a name of random day of the week.
 
FAKER_CXX_EXPORT std::string_view weekdayAbbreviatedName ()
 Returns an abbreviated name of random day of the week.
 
FAKER_CXX_EXPORT std::string_view monthName ()
 Returns a random name of a month.
 
FAKER_CXX_EXPORT std::string_view monthAbbreviatedName ()
 Returns an abbreviated name of random month.
 
FAKER_CXX_EXPORT unsigned year ()
 Returns random year.
 
FAKER_CXX_EXPORT unsigned month ()
 Returns random month.
 
FAKER_CXX_EXPORT unsigned hour ()
 Returns random hour.
 
FAKER_CXX_EXPORT unsigned minute ()
 Returns random minute.
 
FAKER_CXX_EXPORT unsigned second ()
 Returns random second.
 
FAKER_CXX_EXPORT std::string time ()
 Returns random time string.
 
FAKER_CXX_EXPORT unsigned dayOfMonth ()
 Returns random day of month.
 
FAKER_CXX_EXPORT unsigned dayOfWeek ()
 Returns random day of week.
 
FAKER_CXX_EXPORT std::string_view timezoneRandom ()
 Returns random timezone.
 
FAKER_CXX_EXPORT std::string between (int64_t from, int64_t to, DateFormat dateFormat=DateFormat::ISO)
 Generates a random date between two given Unix timestamps.
 
FAKER_CXX_EXPORT std::string between (const std::string &from, const std::string &to, DateFormat dateFormat)
 Generates a random date between two given ISO date strings.
 

Enumeration Type Documentation

◆ DateFormat

enum class faker::date::DateFormat
strong
Enumerator
ISO 
Timestamp 

Function Documentation

◆ anytime()

FAKER_CXX_EXPORT std::string faker::date::anytime ( DateFormat dateFormat = DateFormat::ISO)

Generates a random date between UNIX epoch and 200 years from now.

Parameters
dateFormatSpecifies the format of the output date. Defaults to `DateFormatISO`.
Returns
ISO formatted string.
faker::date::anytime() // "2023-12-08T19:31:32Z"
faker::date::anytime(DateFormat::ISO) // "2020-06-16T15:24:09Z"
faker::date::anytime(DateFormat::Timestamp) // "1592321049"
DateFormat
Definition date.h:11
FAKER_CXX_EXPORT std::string anytime(DateFormat dateFormat=DateFormat::ISO)
Generates a random date between UNIX epoch and 200 years from now.
Definition airline.h:9

◆ between() [1/2]

FAKER_CXX_EXPORT std::string faker::date::between ( const std::string & from,
const std::string & to,
DateFormat dateFormat )

Generates a random date between two given ISO date strings.

Parameters
fromThe starting ISO date string in the format "YYYY-MM-DDTHH:MM:SSZ".
toThe ending ISO date string in the format "YYYY-MM-DDTHH:MM:SSZ".
dateFormatSpecifies the format of the output date, either as an ISO string or a Unix timestamp.
Returns
A string representing the random date in the specified format.
faker::date::between("2021-01-01T00:00:00Z", "2022-01-01T00:00:00Z", DateFormat::ISO); // Returns a random date
between Jan 1, 2021, and Jan 1, 2022, formatted as "2021-06-15T12:34:56Z"
faker::date::between("2021-01-01T00:00:00Z", "2022-01-01T00:00:00Z", DateFormat::Timestamp); // Returns the Unix
timestamp of a random date between Jan 1, 2021, and Jan 1, 2022
FAKER_CXX_EXPORT std::string between(int64_t from, int64_t to, DateFormat dateFormat=DateFormat::ISO)
Generates a random date between two given Unix timestamps.

◆ between() [2/2]

FAKER_CXX_EXPORT std::string faker::date::between ( int64_t from,
int64_t to,
DateFormat dateFormat = DateFormat::ISO )

Generates a random date between two given Unix timestamps.

Parameters
fromThe starting Unix timestamp (seconds since the Unix epoch).
toThe ending Unix timestamp (seconds since the Unix epoch).
dateFormatSpecifies the format of the output date, either as an ISO string or a Unix timestamp.
Returns
A string representing the random date in the specified format.
faker::date::between(1609459200, 1640995200, DateFormat::ISO); // Returns a random date between Jan 1, 2021, and Jan
1, 2022, formatted as "2021-06-15T12:34:56Z" faker::date::between(1609459200, 1640995200, DateFormat::Timestamp); //
Returns the Unix timestamp of a random date between Jan 1, 2021, and Jan 1, 2022

◆ birthdateByAge()

FAKER_CXX_EXPORT std::string faker::date::birthdateByAge ( int minAge = 18,
int maxAge = 80,
DateFormat dateFormat = DateFormat::ISO )

Generates a random birthdate by age.

Parameters
minAgeThe minimum age to generate a birthdate. Defaults to `18`.
maxAgeThe maximum age to generate a birthdate. Defaults to `80`.
dateFormatSpecifies the format of the output date. Defaults to `DateFormatISO`.
Returns
ISO formatted string.
faker::date::birthdateByAge() // "2002-12-07T23:20:12Z"
faker::date::birthdateByAge(20, 30) // "1996-11-14T11:27:09Z"
faker::date::birthdateByAge(20, 30, DateFormat::ISO) // "1996-11-14T11:27:09Z"
faker::date::birthdateByAge(20, 30, DateFormat::Timestamp) // "1718229989"
FAKER_CXX_EXPORT std::string birthdateByAge(int minAge=18, int maxAge=80, DateFormat dateFormat=DateFormat::ISO)
Generates a random birthdate by age.

◆ birthdateByYear()

FAKER_CXX_EXPORT std::string faker::date::birthdateByYear ( int minYear = 1920,
int maxYear = 2000,
DateFormat dateFormat = DateFormat::ISO )

Generates a random birthdate by year.

Parameters
minYearThe minimum year to generate a birthdate. Defaults to `1920`.
maxYearThe maximum year to generate a birthdate. Defaults to `2000`.
dateFormatSpecifies the format of the output date. Defaults to `DateFormatISO`.
Returns
ISO formatted string.
faker::date::birthdateByYear() // "1965-02-19T02:19:47Z"
faker::date::birthdateByYear(1996, 1996) // "1996-05-19T12:00:23Z"
faker::date::birthdateByYear(1996, 1996, DateFormat::ISO) // "1996-05-19T12:00:23Z"
faker::date::birthdateByYear(1996, 1996, DateFormat::Timestamp) // "1718229989"
FAKER_CXX_EXPORT std::string birthdateByYear(int minYear=1920, int maxYear=2000, DateFormat dateFormat=DateFormat::ISO)
Generates a random birthdate by year.

◆ dayOfMonth()

FAKER_CXX_EXPORT unsigned faker::date::dayOfMonth ( )

Returns random day of month.

Returns
A random day of month.
FAKER_CXX_EXPORT unsigned dayOfMonth()
Returns random day of month.

◆ dayOfWeek()

FAKER_CXX_EXPORT unsigned faker::date::dayOfWeek ( )

Returns random day of week.

Returns
A random day of week.
FAKER_CXX_EXPORT unsigned dayOfWeek()
Returns random day of week.

◆ futureDate()

FAKER_CXX_EXPORT std::string faker::date::futureDate ( int years = 1,
DateFormat dateFormat = DateFormat::ISO )

Generates a random date in the future.

Parameters
yearsThe range of years the date may be in the future. Defaults to `1`.
dateFormatSpecifies the format of the output date. Defaults to `DateFormatISO`.
Returns
ISO formatted string.
faker::date::futureDate() // "2023-09-27T09:47:46Z"
faker::date::futureDate(5) // "2024-06-11T19:46:29Z"
faker::date::futureDate(5, DateFormat::ISO) // "2024-06-11T19:46:29Z"
faker::date::futureDate(5, DateFormat::Timestamp) // "1718229989"
FAKER_CXX_EXPORT std::string futureDate(int years=1, DateFormat dateFormat=DateFormat::ISO)
Generates a random date in the future.

◆ hour()

FAKER_CXX_EXPORT unsigned faker::date::hour ( )

Returns random hour.

Returns
A random month.
FAKER_CXX_EXPORT unsigned hour()
Returns random hour.

◆ minute()

FAKER_CXX_EXPORT unsigned faker::date::minute ( )

Returns random minute.

Returns
A random minute.
FAKER_CXX_EXPORT unsigned minute()
Returns random minute.

◆ month()

FAKER_CXX_EXPORT unsigned faker::date::month ( )

Returns random month.

Returns
A random month.
FAKER_CXX_EXPORT unsigned month()
Returns random month.

◆ monthAbbreviatedName()

FAKER_CXX_EXPORT std::string_view faker::date::monthAbbreviatedName ( )

Returns an abbreviated name of random month.

Returns
Abbreviated name of the month.
FAKER_CXX_EXPORT std::string_view monthAbbreviatedName()
Returns an abbreviated name of random month.

◆ monthName()

FAKER_CXX_EXPORT std::string_view faker::date::monthName ( )

Returns a random name of a month.

Returns
Name of the month.
faker::date::monthName() // "October"
FAKER_CXX_EXPORT std::string_view monthName()
Returns a random name of a month.

◆ pastDate()

FAKER_CXX_EXPORT std::string faker::date::pastDate ( int years = 1,
DateFormat dateFormat = DateFormat::ISO )

Generates a random date in the past.

Parameters
yearsThe range of years the date may be in the past. Defaults to `1`.
dateFormatSpecifies the format of the output date. Defaults to `DateFormatISO`.
Returns
ISO formatted string.
faker::date::pastDate() // "2023-12-08T19:31:32Z"
faker::date::pastDate(5) // "2020-06-16T15:24:09Z"
faker::date::pastDate(5, DateFormat::ISO) // "2020-06-16T15:24:09Z"
faker::date::pastDate(5, DateFormat::Timestamp) // "1592321049"
FAKER_CXX_EXPORT std::string pastDate(int years=1, DateFormat dateFormat=DateFormat::ISO)
Generates a random date in the past.

◆ recentDate()

FAKER_CXX_EXPORT std::string faker::date::recentDate ( int days = 3,
DateFormat dateFormat = DateFormat::ISO )

Generates a random date in the recent past.

Parameters
daysThe range of days the date may be in the past. Defaults to `3`.
dateFormatSpecifies the format of the output date. Defaults to `DateFormatISO`.
Returns
ISO formatted string.
faker::date::recentDate() // "2023-07-05T14:12:40Z"
faker::date::recentDate(10) // "2023-06-29T18:24:12Z"
faker::date::recentDate(10, DateFormat::ISO) // "2023-06-29T18:24:12Z"
faker::date::recentDate(10, DateFormat::Timestamp) // "1718229989"
FAKER_CXX_EXPORT std::string recentDate(int days=3, DateFormat dateFormat=DateFormat::ISO)
Generates a random date in the recent past.

◆ second()

FAKER_CXX_EXPORT unsigned faker::date::second ( )

Returns random second.

Returns
A random second.
FAKER_CXX_EXPORT unsigned second()
Returns random second.

◆ soonDate()

FAKER_CXX_EXPORT std::string faker::date::soonDate ( int days = 3,
DateFormat dateFormat = DateFormat::ISO )

Generates a random date in the soon future.

Parameters
daysThe range of days the date may be in the future. Defaults to `3`.
dateFormatSpecifies the format of the output date. Defaults to `DateFormatISO`.
Returns
ISO formatted string.
faker::date::soonDate() // "2023-07-07T18:19:12Z"
faker::date::soonDate(10) // "2023-07-15T09:59:11Z"
faker::date::soonDate(10, DateFormat::ISO) // "2023-07-15T09:59:11Z"
faker::date::soonDate(10, DateFormat::Timestamp) // "1718229989"
FAKER_CXX_EXPORT std::string soonDate(int days=3, DateFormat dateFormat=DateFormat::ISO)
Generates a random date in the soon future.

◆ time()

FAKER_CXX_EXPORT std::string faker::date::time ( )

Returns random time string.

Returns
A random time string.
FAKER_CXX_EXPORT std::string time()
Returns random time string.

◆ timezoneRandom()

FAKER_CXX_EXPORT std::string_view faker::date::timezoneRandom ( )

Returns random timezone.

Returns
A random timezone.
FAKER_CXX_EXPORT std::string_view timezoneRandom()
Returns random timezone.

◆ weekdayAbbreviatedName()

FAKER_CXX_EXPORT std::string_view faker::date::weekdayAbbreviatedName ( )

Returns an abbreviated name of random day of the week.

Returns
Abbreviated name of the weekday.
FAKER_CXX_EXPORT std::string_view weekdayAbbreviatedName()
Returns an abbreviated name of random day of the week.

◆ weekdayName()

FAKER_CXX_EXPORT std::string_view faker::date::weekdayName ( )

Returns a name of random day of the week.

Returns
Name of the weekday.
FAKER_CXX_EXPORT std::string_view weekdayName()
Returns a name of random day of the week.

◆ year()

FAKER_CXX_EXPORT unsigned faker::date::year ( )

Returns random year.

Returns
A random year.
FAKER_CXX_EXPORT unsigned year()
Returns random year.