crawlserv++  [under development]
Application for crawling and analyzing textual content of websites.
crawlservpp::Helper::DateTime Namespace Reference

Namespace for global date/time helper functions. More...

Classes

class  Exception
 Class for date/time exceptions. More...
 
class  LocaleException
 Class for date/time locale exception. More...
 

Constants

constexpr auto longDateTime {"%a, %d %b %Y %T %Z"}
 The 'long' format for date/times. More...
 
constexpr auto unixTimeFormat {"UNIX"sv}
 The keyword to use a UNIX time format. More...
 
constexpr auto unixTimeFormatPlus {"UNIX+"sv}
 The keyword to use a UNIX time format plus an offset. More...
 
constexpr auto unixTimeFormatMinus {"UNIX-"sv}
 The keyword to use a UNIX time format minus an offset. More...
 
constexpr auto unixTimeFormatXLength {5}
 The length of the keyword to use a UNIX time format with offset. More...
 
constexpr auto unixTimeFormatXOffset {4}
 The position of the beginning of a UNIX time format offset. More...
 
constexpr std::array englishOrdinalSuffixes
 An array containing English ordinal suffixes to be stripped from numbers. More...
 
constexpr std::array frenchOrdinalSuffixes
 An array containing French ordinal suffix to be stripped from numbers. More...
 
constexpr std::array russianOrdinalSuffixes
 An array containing Russian ordinal suffixes to be stripped from numbers. More...
 
constexpr std::array ukrainianOrdinalSuffixes
 An array containing Ukrainian ordinal suffixes to be stripped from numbers. More...
 
constexpr auto sqlTimeStamp {"%F %T"}
 The date/time format used by the MySQL database (as C string). More...
 
constexpr auto sqlTimeStampLength {19}
 The length of a formatted time stamp in the MySQL database. More...
 
constexpr auto englishLocalePrefix {"en"sv}
 The prefix for English locales. More...
 
constexpr auto frenchLocalePrefix {"fr"sv}
 The prefix for French locales. More...
 
constexpr auto russianLocalePrefix {"ru"sv}
 The prefix for Russian locales. More...
 
constexpr auto ukrainianLocalePrefix {"uk"sv}
 The prefix for Ukrainian locales. More...
 
constexpr auto finnishLocalePrefix {"fi"sv}
 The prefix for Finnish locales. More...
 
constexpr auto amPmLength {2}
 The length of the 12-h suffix (AM / PM). More...
 
constexpr auto hourChange {12}
 The number of hours to be added to a PM time, or to be subtracted from a 12th hour AM time. More...
 
constexpr auto hourNoonMidnight {12}
 The hour of noon and midnight. More...
 
constexpr auto centuryFrom {69}
 The two digits from which two-digit years will be interpreted as years after 2000. More...
 
constexpr auto yearsPerCentury {100}
 The number of years in a century. More...
 
constexpr auto microsecondsPerDay {86400000000}
 The number of microseconds per day used for date/time formatting. More...
 
constexpr auto millisecondsPerDay {86400000}
 The number of milliseconds per day used for date/time formatting. More...
 
constexpr auto secondsPerDay {86400}
 The number of seconds per day used for date/time formatting. More...
 
constexpr auto microsecondsPerHour {3600000000}
 The number of microseconds per hour used for date/time formatting. More...
 
constexpr auto millisecondsPerHour {3600000}
 The number of milliseconds per hour used for date/time formatting. More...
 
constexpr auto secondsPerHour {3600}
 The number of seconds per hour used for date/time formatting. More...
 
constexpr auto microsecondsPerMinute {60000000}
 The number of microseconds per minute used for date/time formatting. More...
 
constexpr auto millisecondsPerMinute {60000}
 The number of milliseconds per minute used for date/time formatting. More...
 
constexpr auto secondsPerMinute {60}
 The number of seconds per minute used for date/time formatting. More...
 
constexpr auto microsecondsPerSecond {1000000}
 The number of microseconds per second used for date/time formatting. More...
 
constexpr auto millisecondsPerSecond {1000}
 The number of milliseconds per second used for date/time formatting. More...
 
constexpr auto microsecondsPerMillisecond {1000}
 The number of microseconds per millisecond used for date/time formatting. More...
 
constexpr auto isoDateLength {10}
 The length of a date in valid ISO format (YYYY-MM-DD). More...
 
constexpr auto yearLength {4}
 The length of a year. More...
 
constexpr auto isoMonthPos {5}
 The position of the month in an ISO date (YYYY-MM-DD). More...
 
constexpr auto isoMonthLength {2}
 The length of the month in an ISO date (YYYY-MM-DD). More...
 
constexpr auto minTwoDigitYear {1969}
 Consider two-digit years before this year as being in the 2000s. More...
 
constexpr auto base10 {10}
 Base of decimal numbers. More...
 
constexpr auto reducedToMonthLength {7}
 Length of date, reduced to month (YYYY-MM) More...
 
constexpr auto daysPerWeek {7}
 Number of days in a week. More...
 
constexpr std::uint8_t dateWeeks {0}
 Group dates by weeks. More...
 
constexpr std::uint8_t dateDays {1}
 Group dates by days. More...
 
constexpr std::uint8_t dateMonths {2}
 Group dates by months. More...
 
constexpr std::uint8_t dateYears {3}
 Group dates by years. More...
 

Conversion

void convertLongDateTimeToSQLTimeStamp (std::string &dateTime)
 Converts a date/time formatted in a “long” format into the format YYYY-MM-DD HH:MM:SS. More...
 
void convertCustomDateTimeToSQLTimeStamp (std::string &dateTime, const std::string &customFormat)
 Converts date/time with a custom format into the format YYYY-MM-DD HH:MM:SS. More...
 
void convertCustomDateTimeToSQLTimeStamp (std::string &dateTime, const std::string &customFormat, const std::string &locale)
 Converts date/time with a custom format into the format YYYY-MM-DD HH:MM:SS. More...
 
void convertTimeStampToSQLTimeStamp (std::string &timeStamp)
 Converts a timestamp in the YYYYMMDDHHMMSS format to a MySQL timestamp in the YYYY-MM-DD HH:MM:SS format. More...
 
void convertSQLTimeStampToTimeStamp (std::string &timeStamp)
 Converts a MySQL timestamp in the YYYY-MM-DD HH:MM:SS format to a timestamp in the YYYYMMDDHHMMSS format. More...
 
void convert12hTo24h (int &hour, bool isPm)
 Converts an hour from the 12h to the 24h system. More...
 
std::string getYearAndWeek (const std::string &date)
 Get the year and the ISO week number for a specific date. More...
 
void reduceDate (std::string &date, std::uint8_t resolution)
 Reduce a date to the specified resolution. More...
 

Formatting

std::string microsecondsToString (std::uint64_t microseconds)
 Converts microseconds into a well-formatted string. More...
 
std::string millisecondsToString (std::uint64_t milliseconds)
 Converts milliseconds into a well-formatted string. More...
 
std::string secondsToString (std::uint64_t seconds)
 Converts seconds into a well-formatted string. More...
 
std::string now ()
 Formats the current date/time as string in the format YYYY-MM-DD HH:MM:SS. More...
 

Verification

bool isValidISODate (const std::string &isoDate)
 Checks whether a string contains a valid date in the ISO format. More...
 

Comparison

bool isISODateInRange (std::string_view isoDate, std::string_view rangeFrom, std::string_view rangeTo)
 Checks whether the given ISO date is in the given range of dates. More...
 

Gaps inbetween Dates

std::vector< std::string > getDateGap (const std::string &first, const std::string &second, std::uint8_t resolution)
 Gets all dates that lies between two dates. More...
 
std::vector< std::string > getWeekGap (const std::string &first, const std::string &second)
 Gets all ISO week numbers that lie inbetween two week numbers. More...
 
std::vector< std::string > getDayGap (const std::string &first, const std::string &second)
 Gets all days that lie inbetween two dates. More...
 
std::vector< std::string > getMonthGap (const std::string &first, const std::string &second)
 Gets all months that lie inbetween two months. More...
 
std::vector< std::string > getYearGap (const std::string &first, const std::string &second)
 Gets all years that lies inbetween two years. More...
 

Helpers

template<std::size_t N>
void removeOrdinals (const std::array< std::string_view, N > &suffixes, std::string &strInOut)
 Removes all ordinal suffixes after numbers in the given string. More...
 
template<std::size_t N>
void removeOrdinals (std::string_view currentLocale, std::string_view localePrefix, const std::array< std::string_view, N > &suffixes, std::string &strInOut)
 Removes all ordinal suffixes after numbers in the given string, if the current locale matches the given locale. More...
 
void fixFrenchMonths (std::string_view locale, std::string &strInOut)
 Replaces the abbreviation avr. for the month of april (avril) in the given string, if the locale is French. More...
 
void fixRussianMonths (std::string_view locale, std::string &strInOut, std::string &formatInOut)
 Shortens Russian month names and replaces the abbreviations май and сент, if the locale is Russian. More...
 
void fixUkrainianMonths (std::string_view locale, std::string &strInOut, std::string &formatInOut)
 Shortens Ukrainian month names, if the locale is Ukrainian. More...
 
void fixFinnishMonths (std::string_view locale, std::string_view format, std::string &strInOut)
 Fixes semi-abbreviated Finnish month names (huhtik, touko, etc.), if the locale is Finnish. More...
 
void extendSingleDigits (std::string &dateTimeString)
 Extends single digits (1-9) by adding a leading zero to each of them. More...
 
void fixYear (std::string &sqlTimeStamp, std::string_view format)
 Changes a year before 1969 into a year after 2000, if it has been parsed from two digits. More...
 
void handle12hTime (std::string &formatString, const std::string &dateTimeString, bool &outIsAm, bool &outIsPm)
 Handles 12h-time manually to avoid buggy standard library implementations. More...
 

Detailed Description

Namespace for global date/time helper functions.

Function Documentation

◆ convert12hTo24h()

void crawlservpp::Helper::DateTime::convert12hTo24h ( int &  hour,
bool  isPm 
)
inline

Converts an hour from the 12h to the 24h system.

Parameters
hourReference to the hour which will be changed accordingly, if necessary.
isPmIndicates whether the given hour is PM. If false, it will be interpreted as AM.

References hourChange, and hourNoonMidnight.

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ convertCustomDateTimeToSQLTimeStamp() [1/2]

void crawlservpp::Helper::DateTime::convertCustomDateTimeToSQLTimeStamp ( std::string &  dateTime,
const std::string &  customFormat 
)
inline

Converts date/time with a custom format into the format YYYY-MM-DD HH:MM:SS.

Calling this function with an empty input string will have no consequences.

For more information on format strings, see Howard Hinnant's paper about his date.h library.

Alternatively, UNIX, UNIX+<offset>, or UNIX<-offset> can be used to convert from a UNIX time plus/minus the given offset.

Note
A string view cannot be used, because the underlying C function requires a null-terminated string.
Parameters
dateTimeReference to a string containing the date/time formatted in the custom format and to be converted in situ.
customFormatA const reference to the string containing the date/time format to be converted from.
Exceptions
DateTime::Exceptionof the custom format is invalid or empty, or if the date/time conversion fails.

References convert12hTo24h(), englishOrdinalSuffixes, extendSingleDigits(), fixYear(), handle12hTime(), removeOrdinals(), sqlTimeStamp, sqlTimeStampLength, unixTimeFormat, unixTimeFormatMinus, unixTimeFormatPlus, unixTimeFormatXLength, and unixTimeFormatXOffset.

Referenced by convertCustomDateTimeToSQLTimeStamp(), convertLongDateTimeToSQLTimeStamp(), convertTimeStampToSQLTimeStamp(), crawlservpp::Module::Parser::Thread::onReset(), crawlservpp::Module::Extractor::Thread::onReset(), and crawlservpp::Main::Server::tick().

◆ convertCustomDateTimeToSQLTimeStamp() [2/2]

void crawlservpp::Helper::DateTime::convertCustomDateTimeToSQLTimeStamp ( std::string &  dateTime,
const std::string &  customFormat,
const std::string &  locale 
)
inline

Converts date/time with a custom format into the format YYYY-MM-DD HH:MM:SS.

Calling this function with an empty input string will have no consequences.

For more information on format strings, see Howard Hinnant's paper about his date.h library.

Note
String views cannot be used, because the underlying functions require null-terminated strings.
Parameters
dateTimeA reference to the string containing the date/time formatted in the custom format and to be converted in situ.
customFormatA const reference to the string containing the date/time format to be converted from.
localeA const reference to the string containing the locale to be used during the conversion.
Exceptions
DateTime::Exceptionof the custom format is invalid or empty, or if the date/time conversion fails.

References convert12hTo24h(), convertCustomDateTimeToSQLTimeStamp(), englishOrdinalSuffixes, extendSingleDigits(), fixFinnishMonths(), fixFrenchMonths(), fixRussianMonths(), fixUkrainianMonths(), fixYear(), frenchLocalePrefix, frenchOrdinalSuffixes, handle12hTime(), removeOrdinals(), russianLocalePrefix, russianOrdinalSuffixes, sqlTimeStamp, sqlTimeStampLength, ukrainianLocalePrefix, and ukrainianOrdinalSuffixes.

◆ convertLongDateTimeToSQLTimeStamp()

void crawlservpp::Helper::DateTime::convertLongDateTimeToSQLTimeStamp ( std::string &  dateTime)
inline

Converts a date/time formatted in a “long” format into the format YYYY-MM-DD HH:MM:SS.

Calling this function with an empty input string will have no consequences.

Parameters
dateTimeString containing the date/time formatted in a “long” format and to be converted in situ.
Exceptions
DateTime::Exceptionif the conversion fails.
See also
convertCustomDateTimeToSQLTimeStamp

References convertCustomDateTimeToSQLTimeStamp(), and longDateTime.

Referenced by crawlservpp::Module::Crawler::Thread::onReset().

◆ convertSQLTimeStampToTimeStamp()

void crawlservpp::Helper::DateTime::convertSQLTimeStampToTimeStamp ( std::string &  timeStamp)
inline

Converts a MySQL timestamp in the YYYY-MM-DD HH:MM:SS format to a timestamp in the YYYYMMDDHHMMSS format.

Calling this function with an empty input string will have no consequences.

Parameters
timeStampA reference to the string containing a MySQL timestamp in the YYYY-MM-DD HH:MM:SS format to be converted in situ.
Exceptions
DateTime::Exceptionif the conversion fails.
See also
convertTimeStampToSQLTimeStamp

Referenced by crawlservpp::Module::Crawler::Thread::onReset().

◆ convertTimeStampToSQLTimeStamp()

void crawlservpp::Helper::DateTime::convertTimeStampToSQLTimeStamp ( std::string &  timeStamp)
inline

Converts a timestamp in the YYYYMMDDHHMMSS format to a MySQL timestamp in the YYYY-MM-DD HH:MM:SS format.

Calling this function with an empty input string will have no consequences.

Parameters
timeStampA reference to the string containing a timestamp in the YYYYMMDDHHMMSS format to be converted in situ.
Exceptions
DateTime::Exceptionif the conversion fails.
See also
convertCustomDateTimeToSQLTimeStamp

References convertCustomDateTimeToSQLTimeStamp().

Referenced by crawlservpp::Module::Crawler::Thread::onReset().

◆ extendSingleDigits()

void crawlservpp::Helper::DateTime::extendSingleDigits ( std::string &  dateTimeString)
inline

Extends single digits (1-9) by adding a leading zero to each of them.

Parameters
dateTimeStringReference to the string in which all single digits will be extended.

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ fixFinnishMonths()

void crawlservpp::Helper::DateTime::fixFinnishMonths ( std::string_view  locale,
std::string_view  format,
std::string &  strInOut 
)
inline

Fixes semi-abbreviated Finnish month names (huhtik, touko, etc.), if the locale is Finnish.

If the given locale is not Finnish, the function call will be without consequences.

If abbreviated month names (b) are not considered in the given format string, the function call will be without consequences.

Parameters
localeA string view containing the locale to be checked for Finnish.
formatA reference to the string containing the formatting string that will be checked for abbreviated month names (b).
strInOutA reference to the string containing the date/time, in which the semi-abbreviated months will be replaced, if the given locale is Finnish.

References finnishLocalePrefix, and crawlservpp::Helper::Strings::replaceAll().

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ fixFrenchMonths()

void crawlservpp::Helper::DateTime::fixFrenchMonths ( std::string_view  locale,
std::string &  strInOut 
)
inline

Replaces the abbreviation avr. for the month of april (avril) in the given string, if the locale is French.

If the given locale is not French, the function call will be without consequences.

Parameters
localeA string view containing the locale to be checked for French.
strInOutA reference to the string containing the date/time, in which the abbreviation will be replaced if the given locale is French.

References frenchLocalePrefix, and crawlservpp::Helper::Strings::replaceAll().

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ fixRussianMonths()

void crawlservpp::Helper::DateTime::fixRussianMonths ( std::string_view  locale,
std::string &  strInOut,
std::string &  formatInOut 
)
inline

Shortens Russian month names and replaces the abbreviations май and сент, if the locale is Russian.

If the given locale is English, and the format contains b or B, the function will replace the Russified month names maj, Maj and MAJ with the English May.

Otherwise, the function call will be without consequences.

Parameters
localeA string view containing the locale to be checked for Russian or English.
strInOutA reference to the string containing the date/time, in which the months will be replaced, if the given locale is Russian or English.
formatInOutA reference to the string containing the formatting string that will be changed accordingly, if necessary.

References englishLocalePrefix, crawlservpp::Helper::Strings::replaceAll(), and russianLocalePrefix.

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ fixUkrainianMonths()

void crawlservpp::Helper::DateTime::fixUkrainianMonths ( std::string_view  locale,
std::string &  strInOut,
std::string &  formatInOut 
)
inline

Shortens Ukrainian month names, if the locale is Ukrainian.

If the given locale is not Ukrainian, the function call will be without consequences.

Parameters
localeA string view containing the locale to be checked for Ukrainian.
strInOutA reference to the string containing the date/time, in which the months will be replaced, if the given locale is Ukrainian.
formatInOutA reference to the string containing the formatting string that will be changed accordingly, if necessary.

References crawlservpp::Helper::Strings::replaceAll(), and ukrainianLocalePrefix.

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ fixYear()

void crawlservpp::Helper::DateTime::fixYear ( std::string &  sqlTimeStamp,
std::string_view  format 
)
inline

Changes a year before 1969 into a year after 2000, if it has been parsed from two digits.

Parameters
sqlTimeStampReference to the string containing the timestamp that will be changed, if necessary.
formatView to the string containing the format. If it does not contain y, the call to the function will have no effect.

References base10, minTwoDigitYear, and yearLength.

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ getDateGap()

std::vector< std::string > crawlservpp::Helper::DateTime::getDateGap ( const std::string &  first,
const std::string &  second,
std::uint8_t  resolution 
)
inline

Gets all dates that lies between two dates.

Parameters
firstConstant reference to a string containing the first date.
secondConstant reference to a string containing the second date.
resolutionResolution of the dates.
Returns
A vector containing all dates that lies inbetween the two dates in the given resolution.
Exceptions
DateTime::Exceptionif the given dates cannot be converted according to the specified resolution, or the specified resolution is invalid.
See also
dateWeeks, dateDays, dateMonths, dateYears, getWeekGap, getDayGap, getMonthGap, getYearGap

References dateDays, dateMonths, dateWeeks, dateYears, getDayGap(), getMonthGap(), getWeekGap(), and getYearGap().

Referenced by crawlservpp::Module::Analyzer::Algo::WordsOverTime::resetAlgo(), crawlservpp::Module::Analyzer::Algo::AssocOverTime::resetAlgo(), and crawlservpp::Module::Analyzer::Algo::SentimentOverTime::resetAlgo().

◆ getDayGap()

std::vector< std::string > crawlservpp::Helper::DateTime::getDayGap ( const std::string &  first,
const std::string &  second 
)
inline

Gets all days that lie inbetween two dates.

Parameters
firstConstant reference to a string containing the first date in the ISO format, i.e. YYYY-MM-DD.
secondConstant reference to a string containing the second date in the ISO format, i.e. YYYY-MM-DD.
Returns
A vector containing all dates that lie inbetween the first and the second date in ISO format, i.e. YYYY-MM-DD. An empty vector if the given dates are equal or follow each other.
Exceptions
DateTime::Exceptionif the given dates cannot be converted, i.e. their format is invalid.
See also
getDateGap, getWeekGap, getMonthGap, getYearGap

Referenced by getDateGap().

◆ getMonthGap()

std::vector< std::string > crawlservpp::Helper::DateTime::getMonthGap ( const std::string &  first,
const std::string &  second 
)
inline

Gets all months that lie inbetween two months.

Parameters
firstConstant reference to a string containing the first month in the format YYYY-MM.
secondConstant reference to a string containing the second month in the format YYYY-MM.
Returns
A vector containing all months that lie inbetween the first and the second month, in the format YYYY-MM. An empty vector if the given months are equal or follow each other.
Exceptions
DateTime::Exceptionif the given months cannot be converted, i.e. their format is invalid.
See also
getDateGap, getWeekGap, getDayGap, getYearGap

Referenced by getDateGap().

◆ getWeekGap()

std::vector< std::string > crawlservpp::Helper::DateTime::getWeekGap ( const std::string &  first,
const std::string &  second 
)
inline

Gets all ISO week numbers that lie inbetween two week numbers.

For more information on ISO week numbers, see https://www.epochconverter.com/weeknumbers.

Parameters
firstConstant reference to a string containing the first week in the format YYYY-#WW.
secondConstant reference to a string containing the second week in the format YYYY-#WW.
Returns
A vector containing all weeks that lie inbetween the first and the second week, in the format YYYY-#WW. An empty vector if the given weeks are equal or follow each other.
Exceptions
DateTime::Exceptionif the given weeks cannot be converted, i.e. their format is invalid.
See also
getDateGap, getMonthGap, getDayGap, getYearGap

References daysPerWeek, and getYearAndWeek().

Referenced by getDateGap().

◆ getYearAndWeek()

std::string crawlservpp::Helper::DateTime::getYearAndWeek ( const std::string &  date)
inline

Get the year and the ISO week number for a specific date.

The year of the ISO week might differ from the week of the specified date.

For more information on ISO week numbers, see https://www.epochconverter.com/weeknumbers.

Parameters
dateConstant reference to a string containing the date in the format YYYY-MM-DD.
Returns
The year and the week number in the format YYYY-#WW.
Exceptions
DateTime::Exceptionif the conversion fails.

Referenced by getWeekGap(), and reduceDate().

◆ getYearGap()

std::vector< std::string > crawlservpp::Helper::DateTime::getYearGap ( const std::string &  first,
const std::string &  second 
)
inline

Gets all years that lies inbetween two years.

Parameters
firstConstant reference to a string containing the first year in the format YYYY.
secondConstant reference to a string containing the second year in the format YYYY.
Returns
A vector containing all years that lie inbetween the first and the second year, in the format YYYY. An empty vector if the given years are equal or follow each other.
Exceptions
DateTime::Exceptionif the given years cannot be converted, i.e. their format is invalid.
See also
getDateGap, getWeekGap, getDayGap, getMonthGap

References crawlservpp::Main::year.

Referenced by getDateGap().

◆ handle12hTime()

void crawlservpp::Helper::DateTime::handle12hTime ( std::string &  formatString,
const std::string &  dateTimeString,
bool &  outIsAm,
bool &  outIsPm 
)
inline

Handles 12h-time manually to avoid buggy standard library implementations.

If the format contains a 12h suffix (p), it will be replaced by the actual content of the suffix. For times after noon (pm), the 12 hours before noon need to be manually added during conversion. For times in the 12th hour, 12 hours need to be subtracted manually from the AM time.

Parameters
formatStringReference to a string containing the format of the date/time.
dateTimeStringConstant reference to a string containing the date/time.
outIsAmReference to a boolean value that will be set to true, if an AM time has been encountered, i.e. during conversion, twelve hours need to be manually subtracted if the given time is in the 12th hour. Otherwise its value will not be changed.
outIsPmReference to a boolean value that will be set to true, if an PM time has been encountered, i.e. during conversion, twelve hours need to be manually added. Otherwise its value will not be changed.
Note
Replaced will be the first am, AM, pm, or PM that is surrounded by white spaces, punctuation, digits and/or the beginning/end of the string, regardless of its actual position.

References amPmLength, and crawlservpp::Helper::Strings::replaceAll().

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ isISODateInRange()

bool crawlservpp::Helper::DateTime::isISODateInRange ( std::string_view  isoDate,
std::string_view  rangeFrom,
std::string_view  rangeTo 
)
inline

Checks whether the given ISO date is in the given range of dates.

Note
Only the first ten characters of the given dates will be considered.
Parameters
isoDateA string view containing the date in valid ISO format, i.e. a date in the format YYY-MM-DD.
rangeFromA string view containing the start date of the range in valid ISO format, i.e. a date in the format YYY-MM-DD.
rangeToA string view containing the end date of the range in valid ISO format, i.e. a date in the format YYY-MM-DD.
Returns
True, if the given date falls into the given range of dates or one of the two dates defining this range are too short. False, if the given date does not fall into the given range of dates, or the given date is too short.

References isoDateLength.

Referenced by crawlservpp::Data::Corpus::filterByDate().

◆ isValidISODate()

bool crawlservpp::Helper::DateTime::isValidISODate ( const std::string &  isoDate)
inline

Checks whether a string contains a valid date in the ISO format.

Note
A string view is not being used, because the underlying string stream requires a copy of the string.
Parameters
isoDateConstant reference to a string containing the date to check.
Returns
True if the given string contains a valid date in ISO format, i.e. a date in the format YYY-MM-DD. False otherwise.

◆ microsecondsToString()

std::string crawlservpp::Helper::DateTime::microsecondsToString ( std::uint64_t  microseconds)
inline

Converts microseconds into a well-formatted string.

Parameters
microsecondsThe number of microseconds to convert.
Returns
A copy of the string containing the well-formatted output.
See also
millisecondsToString, secondsToString

References microsecondsPerDay, microsecondsPerHour, microsecondsPerMillisecond, microsecondsPerMinute, and microsecondsPerSecond.

Referenced by crawlservpp::Timer::SimpleHR::tickStr(), and crawlservpp::Timer::StartStopHR::totalStr().

◆ millisecondsToString()

std::string crawlservpp::Helper::DateTime::millisecondsToString ( std::uint64_t  milliseconds)
inline

Converts milliseconds into a well-formatted string.

Parameters
millisecondsThe number of milliseconds to convert.
Returns
A copy of the string containing the well-formatted output.
See also
microsecondsToString, secondsToString

References millisecondsPerDay, millisecondsPerHour, millisecondsPerMinute, and millisecondsPerSecond.

Referenced by crawlservpp::Timer::Simple::tickStr(), and crawlservpp::Timer::StartStop::totalStr().

◆ now()

std::string crawlservpp::Helper::DateTime::now ( )
inline

Formats the current date/time as string in the format YYYY-MM-DD HH:MM:SS.

Returns
A copy of the string containing the current date/time of the system as string in the format YYYY-MM-DD HH:MM:SS.

Referenced by crawlservpp::Module::Analyzer::Thread::finished(), crawlservpp::Main::Server::getUpTime(), crawlservpp::Module::Database::log(), crawlservpp::Module::Thread::log(), crawlservpp::Module::Parser::Thread::onClear(), crawlservpp::Module::Extractor::Thread::onClear(), crawlservpp::Module::Crawler::Thread::onClear(), crawlservpp::Module::Parser::Thread::onPause(), crawlservpp::Module::Extractor::Thread::onPause(), crawlservpp::Module::Crawler::Thread::onPause(), crawlservpp::Module::Parser::Thread::onReset(), crawlservpp::Module::Extractor::Thread::onReset(), crawlservpp::Module::Crawler::Thread::onReset(), crawlservpp::Module::Analyzer::Thread::onTick(), crawlservpp::Module::Parser::Thread::onTick(), crawlservpp::Module::Extractor::Thread::onTick(), crawlservpp::Module::Parser::Thread::onUnpause(), crawlservpp::Module::Extractor::Thread::onUnpause(), crawlservpp::Module::Crawler::Thread::onUnpause(), crawlservpp::Network::Curl::resetConnection(), crawlservpp::Timer::StartStop::start(), crawlservpp::Timer::StartStopHR::start(), crawlservpp::Timer::StartStop::stop(), crawlservpp::Timer::StartStopHR::stop(), crawlservpp::Timer::SimpleHR::tick(), crawlservpp::Timer::Simple::tick(), crawlservpp::Main::Server::tick(), crawlservpp::Timer::SimpleHR::tickStr(), and crawlservpp::Timer::Simple::tickStr().

◆ reduceDate()

void crawlservpp::Helper::DateTime::reduceDate ( std::string &  date,
std::uint8_t  resolution 
)
inline

Reduce a date to the specified resolution.

Parameters
dateReference to a string containing the date in the format YYYY-MM-DD that will be reduced to the specified resolution, if necessary.
resolutionResolution to be used for reducing the date.
Exceptions
DateTime::Exceptionif the given date/time has an invalid length, or the specified resolution is invalid.
See also
dateWeeks, dateDays, dateMonths, dateYears

References dateDays, dateMonths, dateWeeks, dateYears, getYearAndWeek(), isoDateLength, reducedToMonthLength, and yearLength.

Referenced by crawlservpp::Module::Analyzer::Algo::WordsOverTime::resetAlgo(), crawlservpp::Module::Analyzer::Algo::AssocOverTime::resetAlgo(), and crawlservpp::Module::Analyzer::Algo::SentimentOverTime::resetAlgo().

◆ removeOrdinals() [1/2]

template<std::size_t N>
void crawlservpp::Helper::DateTime::removeOrdinals ( const std::array< std::string_view, N > &  suffixes,
std::string &  strInOut 
)

Removes all ordinal suffixes after numbers in the given string.

Parameters
suffixesConstant reference to an array containing the suffixes to be removed from the end of numbers in the given string.
strInOutA reference to the string containing the date/time, from which the ordinal suffixes will be removed in situ.

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ removeOrdinals() [2/2]

template<std::size_t N>
void crawlservpp::Helper::DateTime::removeOrdinals ( std::string_view  currentLocale,
std::string_view  localePrefix,
const std::array< std::string_view, N > &  suffixes,
std::string &  strInOut 
)

Removes all ordinal suffixes after numbers in the given string, if the current locale matches the given locale.

Parameters
currentLocaleView of a string containing the current locale.
localePrefixView of a string containing the language prefix of the locale of the given suffixes.
suffixesConstant reference to an array containing the suffixes to be removed from the end of numbers in the given string, if the current locale fits the given locale prefix.
strInOutA reference to the string containing the date/time, from which the ordinal suffixes will be removed in situ, if the current locale starts with the given locale prefix.

◆ secondsToString()

std::string crawlservpp::Helper::DateTime::secondsToString ( std::uint64_t  seconds)
inline

Converts seconds into a well-formatted string.

Parameters
secondsThe number of seconds to convert.
Returns
A copy of the string containing the well-formatted output.
See also
microsecondsToString, millisecondsToString

References secondsPerDay, secondsPerHour, and secondsPerMinute.

Referenced by crawlservpp::Main::Database::checkConnection(), crawlservpp::Module::Thread::log(), crawlservpp::Main::Server::tick(), and crawlservpp::Main::App::~App().

Variable Documentation

◆ amPmLength

constexpr auto crawlservpp::Helper::DateTime::amPmLength {2}
inline

The length of the 12-h suffix (AM / PM).

Referenced by handle12hTime().

◆ base10

constexpr auto crawlservpp::Helper::DateTime::base10 {10}
inline

Base of decimal numbers.

Referenced by fixYear().

◆ centuryFrom

constexpr auto crawlservpp::Helper::DateTime::centuryFrom {69}
inline

The two digits from which two-digit years will be interpreted as years after 2000.

◆ dateDays

constexpr std::uint8_t crawlservpp::Helper::DateTime::dateDays {1}
inline

Group dates by days.

See also
reduceDate, getDateGap

Referenced by getDateGap(), and reduceDate().

◆ dateMonths

constexpr std::uint8_t crawlservpp::Helper::DateTime::dateMonths {2}
inline

Group dates by months.

See also
reduceDate, getDateGap

Referenced by getDateGap(), and reduceDate().

◆ dateWeeks

constexpr std::uint8_t crawlservpp::Helper::DateTime::dateWeeks {0}
inline

Group dates by weeks.

See also
reduceDate, getDateGap

Referenced by getDateGap(), and reduceDate().

◆ dateYears

constexpr std::uint8_t crawlservpp::Helper::DateTime::dateYears {3}
inline

Group dates by years.

See also
reduceDate, getDateGap

Referenced by getDateGap(), and reduceDate().

◆ daysPerWeek

constexpr auto crawlservpp::Helper::DateTime::daysPerWeek {7}
inline

Number of days in a week.

Referenced by getWeekGap().

◆ englishLocalePrefix

constexpr auto crawlservpp::Helper::DateTime::englishLocalePrefix {"en"sv}
inline

The prefix for English locales.

Referenced by fixRussianMonths().

◆ englishOrdinalSuffixes

constexpr std::array crawlservpp::Helper::DateTime::englishOrdinalSuffixes
inline
Initial value:
{
"st"sv, "nd"sv, "rd"sv, "th"sv
}

An array containing English ordinal suffixes to be stripped from numbers.

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ finnishLocalePrefix

constexpr auto crawlservpp::Helper::DateTime::finnishLocalePrefix {"fi"sv}
inline

The prefix for Finnish locales.

Referenced by fixFinnishMonths().

◆ frenchLocalePrefix

constexpr auto crawlservpp::Helper::DateTime::frenchLocalePrefix {"fr"sv}
inline

The prefix for French locales.

Referenced by convertCustomDateTimeToSQLTimeStamp(), and fixFrenchMonths().

◆ frenchOrdinalSuffixes

constexpr std::array crawlservpp::Helper::DateTime::frenchOrdinalSuffixes
inline
Initial value:
{
"e"sv, "er"sv
}

An array containing French ordinal suffix to be stripped from numbers.

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ hourChange

constexpr auto crawlservpp::Helper::DateTime::hourChange {12}
inline

The number of hours to be added to a PM time, or to be subtracted from a 12th hour AM time.

Referenced by convert12hTo24h().

◆ hourNoonMidnight

constexpr auto crawlservpp::Helper::DateTime::hourNoonMidnight {12}
inline

The hour of noon and midnight.

Referenced by convert12hTo24h().

◆ isoDateLength

constexpr auto crawlservpp::Helper::DateTime::isoDateLength {10}
inline

The length of a date in valid ISO format (YYYY-MM-DD).

Referenced by isISODateInRange(), and reduceDate().

◆ isoMonthLength

constexpr auto crawlservpp::Helper::DateTime::isoMonthLength {2}
inline

The length of the month in an ISO date (YYYY-MM-DD).

◆ isoMonthPos

constexpr auto crawlservpp::Helper::DateTime::isoMonthPos {5}
inline

The position of the month in an ISO date (YYYY-MM-DD).

◆ longDateTime

constexpr auto crawlservpp::Helper::DateTime::longDateTime {"%a, %d %b %Y %T %Z"}
inline

The 'long' format for date/times.

Referenced by convertLongDateTimeToSQLTimeStamp().

◆ microsecondsPerDay

constexpr auto crawlservpp::Helper::DateTime::microsecondsPerDay {86400000000}
inline

The number of microseconds per day used for date/time formatting.

Referenced by microsecondsToString().

◆ microsecondsPerHour

constexpr auto crawlservpp::Helper::DateTime::microsecondsPerHour {3600000000}
inline

The number of microseconds per hour used for date/time formatting.

Referenced by microsecondsToString().

◆ microsecondsPerMillisecond

constexpr auto crawlservpp::Helper::DateTime::microsecondsPerMillisecond {1000}
inline

The number of microseconds per millisecond used for date/time formatting.

Referenced by microsecondsToString().

◆ microsecondsPerMinute

constexpr auto crawlservpp::Helper::DateTime::microsecondsPerMinute {60000000}
inline

The number of microseconds per minute used for date/time formatting.

Referenced by microsecondsToString().

◆ microsecondsPerSecond

constexpr auto crawlservpp::Helper::DateTime::microsecondsPerSecond {1000000}
inline

The number of microseconds per second used for date/time formatting.

Referenced by microsecondsToString().

◆ millisecondsPerDay

constexpr auto crawlservpp::Helper::DateTime::millisecondsPerDay {86400000}
inline

The number of milliseconds per day used for date/time formatting.

Referenced by millisecondsToString().

◆ millisecondsPerHour

constexpr auto crawlservpp::Helper::DateTime::millisecondsPerHour {3600000}
inline

The number of milliseconds per hour used for date/time formatting.

Referenced by millisecondsToString().

◆ millisecondsPerMinute

constexpr auto crawlservpp::Helper::DateTime::millisecondsPerMinute {60000}
inline

The number of milliseconds per minute used for date/time formatting.

Referenced by millisecondsToString().

◆ millisecondsPerSecond

constexpr auto crawlservpp::Helper::DateTime::millisecondsPerSecond {1000}
inline

The number of milliseconds per second used for date/time formatting.

Referenced by millisecondsToString().

◆ minTwoDigitYear

constexpr auto crawlservpp::Helper::DateTime::minTwoDigitYear {1969}
inline

Consider two-digit years before this year as being in the 2000s.

Referenced by fixYear().

◆ reducedToMonthLength

constexpr auto crawlservpp::Helper::DateTime::reducedToMonthLength {7}
inline

Length of date, reduced to month (YYYY-MM)

Referenced by reduceDate().

◆ russianLocalePrefix

constexpr auto crawlservpp::Helper::DateTime::russianLocalePrefix {"ru"sv}
inline

The prefix for Russian locales.

Referenced by convertCustomDateTimeToSQLTimeStamp(), and fixRussianMonths().

◆ russianOrdinalSuffixes

constexpr std::array crawlservpp::Helper::DateTime::russianOrdinalSuffixes
inline
Initial value:
{
"-ый"sv, "-го"sv, "-му"sv, "-ми"sv, "-й"sv, "-я"sv, "-е"sv, "-м"sv, "-х"sv
}

An array containing Russian ordinal suffixes to be stripped from numbers.

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ secondsPerDay

constexpr auto crawlservpp::Helper::DateTime::secondsPerDay {86400}
inline

The number of seconds per day used for date/time formatting.

Referenced by secondsToString().

◆ secondsPerHour

constexpr auto crawlservpp::Helper::DateTime::secondsPerHour {3600}
inline

The number of seconds per hour used for date/time formatting.

Referenced by secondsToString().

◆ secondsPerMinute

constexpr auto crawlservpp::Helper::DateTime::secondsPerMinute {60}
inline

The number of seconds per minute used for date/time formatting.

Referenced by secondsToString().

◆ sqlTimeStamp

constexpr auto crawlservpp::Helper::DateTime::sqlTimeStamp {"%F %T"}
inline

The date/time format used by the MySQL database (as C string).

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ sqlTimeStampLength

constexpr auto crawlservpp::Helper::DateTime::sqlTimeStampLength {19}
inline

The length of a formatted time stamp in the MySQL database.

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ ukrainianLocalePrefix

constexpr auto crawlservpp::Helper::DateTime::ukrainianLocalePrefix {"uk"sv}
inline

The prefix for Ukrainian locales.

Referenced by convertCustomDateTimeToSQLTimeStamp(), and fixUkrainianMonths().

◆ ukrainianOrdinalSuffixes

constexpr std::array crawlservpp::Helper::DateTime::ukrainianOrdinalSuffixes
inline
Initial value:
{
"-а"sv, "-е"sv, "-і"sv, "-я"sv, "-є"sv
}

An array containing Ukrainian ordinal suffixes to be stripped from numbers.

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ unixTimeFormat

constexpr auto crawlservpp::Helper::DateTime::unixTimeFormat {"UNIX"sv}
inline

The keyword to use a UNIX time format.

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ unixTimeFormatMinus

constexpr auto crawlservpp::Helper::DateTime::unixTimeFormatMinus {"UNIX-"sv}
inline

The keyword to use a UNIX time format minus an offset.

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ unixTimeFormatPlus

constexpr auto crawlservpp::Helper::DateTime::unixTimeFormatPlus {"UNIX+"sv}
inline

The keyword to use a UNIX time format plus an offset.

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ unixTimeFormatXLength

constexpr auto crawlservpp::Helper::DateTime::unixTimeFormatXLength {5}
inline

The length of the keyword to use a UNIX time format with offset.

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ unixTimeFormatXOffset

constexpr auto crawlservpp::Helper::DateTime::unixTimeFormatXOffset {4}
inline

The position of the beginning of a UNIX time format offset.

Referenced by convertCustomDateTimeToSQLTimeStamp().

◆ yearLength

constexpr auto crawlservpp::Helper::DateTime::yearLength {4}
inline

The length of a year.

Referenced by fixYear(), and reduceDate().

◆ yearsPerCentury

constexpr auto crawlservpp::Helper::DateTime::yearsPerCentury {100}
inline

The number of years in a century.