Skip to content

Commit

Permalink
refactor: date module migrate
Browse files Browse the repository at this point in the history
- date module migration from class to functions within date namespace

- changed function name from "timezone" to "timezoneRandom" in date module

- modified reference to variables and functions from date module in git module

- modified reference to function from date module in finance module

- changelog updated

Signed-off-by: Guru Mehar Rachaputi <[email protected]>
  • Loading branch information
00thirdeye00 committed Jun 24, 2024
1 parent e5342e7 commit 50ec64e
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 120 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ All notable changes to this project will be documented in this file
* changed std::string to std::string_view in functions where is was possible
* changed function name from `sport` to `sportName` in sport module
* changed function name from `vehicle` to `vehicleName` in vehicle module
* changed function name from `timezone` to `timezoneRandom` in date module


### Features

Expand Down
118 changes: 57 additions & 61 deletions include/faker-cxx/Date.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

#include <string_view>

namespace faker
namespace faker::date
{
class Date
{
public:
enum class DateFormat
{
ISO,
Expand All @@ -21,13 +18,13 @@ class Date
* @returns ISO formatted string.
*
* @code
* Date::pastDate() // "2023-12-08T19:31:32Z"
* Date::pastDate(5) // "2020-06-16T15:24:09Z"
* Date::pastDate(5, Date::DateFormat::ISO) // "2020-06-16T15:24:09Z"
* Date::pastDate(5, Date::DateFormat::Timestamp) // "1592321049"
* date::pastDate() // "2023-12-08T19:31:32Z"
* date::pastDate(5) // "2020-06-16T15:24:09Z"
* date::pastDate(5, DateFormat::ISO) // "2020-06-16T15:24:09Z"
* date::pastDate(5, DateFormat::Timestamp) // "1592321049"
* @endcode
*/
static std::string pastDate(int years = 1, DateFormat dateFormat = DateFormat::ISO);
std::string pastDate(int years = 1, DateFormat dateFormat = DateFormat::ISO);

/**
* @brief Generates a random date in the future.
Expand All @@ -37,13 +34,13 @@ class Date
* @returns ISO formatted string.
*
* @code
* Date::futureDate() // "2023-09-27T09:47:46Z"
* Date::futureDate(5) // "2024-06-11T19:46:29Z"
* Date::futureDate(5, Date::DateFormat::ISO) // "2024-06-11T19:46:29Z"
* Date::futureDate(5, Date::DateFormat::Timestamp) // "1718229989"
* date::futureDate() // "2023-09-27T09:47:46Z"
* date::futureDate(5) // "2024-06-11T19:46:29Z"
* date::futureDate(5, DateFormat::ISO) // "2024-06-11T19:46:29Z"
* date::futureDate(5, DateFormat::Timestamp) // "1718229989"
* @endcode
*/
static std::string futureDate(int years = 1, DateFormat dateFormat = DateFormat::ISO);
std::string futureDate(int years = 1, DateFormat dateFormat = DateFormat::ISO);

/**
* @brief Generates a random date in the recent past.
Expand All @@ -53,13 +50,13 @@ class Date
* @returns ISO formatted string.
*
* @code
* Date::recentDate() // "2023-07-05T14:12:40Z"
* Date::recentDate(10) // "2023-06-29T18:24:12Z"
* Date::recentDate(10, Date::DateFormat::ISO) // "2023-06-29T18:24:12Z"
* Date::recentDate(10, Date::DateFormat::Timestamp) // "1718229989"
* date::recentDate() // "2023-07-05T14:12:40Z"
* date::recentDate(10) // "2023-06-29T18:24:12Z"
* date::recentDate(10, DateFormat::ISO) // "2023-06-29T18:24:12Z"
* date::recentDate(10, DateFormat::Timestamp) // "1718229989"
* @endcode
*/
static std::string recentDate(int days = 3, DateFormat dateFormat = DateFormat::ISO);
std::string recentDate(int days = 3, DateFormat dateFormat = DateFormat::ISO);

/**
* @brief Generates a random date in the soon future.
Expand All @@ -69,13 +66,13 @@ class Date
* @returns ISO formatted string.
*
* @code
* Date::soonDate() // "2023-07-07T18:19:12Z"
* Date::soonDate(10) // "2023-07-15T09:59:11Z"
* Date::soonDate(10, Date::DateFormat::ISO) // "2023-07-15T09:59:11Z"
* Date::soonDate(10, Date::DateFormat::Timestamp) // "1718229989"
* date::soonDate() // "2023-07-07T18:19:12Z"
* date::soonDate(10) // "2023-07-15T09:59:11Z"
* date::soonDate(10, DateFormat::ISO) // "2023-07-15T09:59:11Z"
* date::soonDate(10, DateFormat::Timestamp) // "1718229989"
* @endcode
*/
static std::string soonDate(int days = 3, DateFormat dateFormat = DateFormat::ISO);
std::string soonDate(int days = 3, DateFormat dateFormat = DateFormat::ISO);

/**
* @brief Generates a random birthdate by age.
Expand All @@ -86,13 +83,13 @@ class Date
* @returns ISO formatted string.
*
* @code
* Date::birthdateByAge() // "2002-12-07T23:20:12Z"
* Date::birthdateByAge(20, 30) // "1996-11-14T11:27:09Z"
* Date::birthdateByAge(20, 30, Date::DateFormat::ISO) // "1996-11-14T11:27:09Z"
* Date::birthdateByAge(20, 30, Date::DateFormat::Timestamp) // "1718229989"
* date::birthdateByAge() // "2002-12-07T23:20:12Z"
* date::birthdateByAge(20, 30) // "1996-11-14T11:27:09Z"
* date::birthdateByAge(20, 30, DateFormat::ISO) // "1996-11-14T11:27:09Z"
* date::birthdateByAge(20, 30, DateFormat::Timestamp) // "1718229989"
* @endcode
*/
static std::string birthdateByAge(int minAge = 18, int maxAge = 80, DateFormat dateFormat = DateFormat::ISO);
std::string birthdateByAge(int minAge = 18, int maxAge = 80, DateFormat dateFormat = DateFormat::ISO);

/**
* @brief Generates a random birthdate by year.
Expand All @@ -103,155 +100,154 @@ class Date
* @returns ISO formatted string.
*
* @code
* Date::birthdateByYear() // "1965-02-19T02:19:47Z"
* Date::birthdateByYear(1996, 1996) // "1996-05-19T12:00:23Z"
* Date::birthdateByYear(1996, 1996, Date::DateFormat::ISO) // "1996-05-19T12:00:23Z"
* Date::birthdateByYear(1996, 1996, Date::DateFormat::Timestamp) // "1718229989"
* date::birthdateByYear() // "1965-02-19T02:19:47Z"
* date::birthdateByYear(1996, 1996) // "1996-05-19T12:00:23Z"
* date::birthdateByYear(1996, 1996, DateFormat::ISO) // "1996-05-19T12:00:23Z"
* date::birthdateByYear(1996, 1996, DateFormat::Timestamp) // "1718229989"
* @endcode
*/
static std::string birthdateByYear(int minYear = 1920, int maxYear = 2000, DateFormat dateFormat = DateFormat::ISO);
std::string birthdateByYear(int minYear = 1920, int maxYear = 2000, DateFormat dateFormat = DateFormat::ISO);

/**
* @brief Returns a name of random day of the week.
*
* @returns Name of the weekday.
*
* @code
* Date::weekdayName() // "Monday"
* date::weekdayName() // "Monday"
* @endcode
*/
static std::string_view weekdayName();
std::string_view weekdayName();

/**
* @brief Returns an abbreviated name of random day of the week.
*
* @returns Abbreviated name of the weekday.
*
* @code
* Date::weekdayAbbreviatedName() // "Mon"
* date::weekdayAbbreviatedName() // "Mon"
* @endcode
*/
static std::string_view weekdayAbbreviatedName();
std::string_view weekdayAbbreviatedName();

/**
* @brief Returns a random name of a month.
*
* @returns Name of the month.
*
* @code
* Date::monthName() // "October"
* date::monthName() // "October"
* @endcode
*/
static std::string_view monthName();
std::string_view monthName();

/**
* @brief Returns an abbreviated name of random month.
*
* @returns Abbreviated name of the month.
*
* @code
* Date::monthAbbreviatedName() // "Feb"
* date::monthAbbreviatedName() // "Feb"
* @endcode
*/
static std::string_view monthAbbreviatedName();
std::string_view monthAbbreviatedName();

/**
* @brief Returns random year.
*
* @returns A random year
*
* @code
* Date::year() // 2000
* date::year() // 2000
* @endcode
*/
static unsigned year();
unsigned year();

/**
* @brief Returns random month.
*
* @returns A random month
*
* @code
* Date::month() // 9
* date::month() // 9
* @endcode
*/
static unsigned month();
unsigned month();

/**
* @brief Returns random hour.
*
* @returns A random month
*
* @code
* Date::hour() // 21
* date::hour() // 21
* @endcode
*/
static unsigned hour();
unsigned hour();

/**
* @brief Returns random minute.
*
* @returns A random minute
*
* @code
* Date::minute() // 40
* date::minute() // 40
* @endcode
*/
static unsigned minute();
unsigned minute();

/**
* @brief Returns random second.
*
* @returns A random second
*
* @code
* Date::second() // 40
* date::second() // 40
* @endcode
*/
static unsigned second();
unsigned second();

/**
* @brief Returns random time string.
*
* @returns A random time string
*
* @code
* Date::time() // 21:40
* date::time() // 21:40
* @endcode
*/
static std::string time();
std::string time();

/**
* @brief Returns random day of month.
*
* @returns A random day of month
*
* @code
* Date::dayOfMonth() // 15
* date::dayOfMonth() // 15
* @endcode
*/
static unsigned dayOfMonth();
unsigned dayOfMonth();

/**
* @brief Returns random day of week.
*
* @returns A random day of week
*
* @code
* Date::dayOfWeek() // 5
* date::dayOfWeek() // 5
* @endcode
*/
static unsigned dayOfWeek();
unsigned dayOfWeek();

/**
* @brief Returns random timezone.
*
* @returns A random timezone
*
* @code
* Date::timezone() // PT
* date::timezoneRandom() // PT
* @endcode
*/
static std::string_view timezone();
};
std::string_view timezoneRandom();
}
Loading

0 comments on commit 50ec64e

Please sign in to comment.