Eazy Datetime Cpp
Public Member Functions | Static Public Member Functions | List of all members
EZ::Datetime Class Reference

Datetime object. More...

#include <datetime.h>

Public Member Functions

 Datetime (const std::string &timestamp, const std::string &format, const bool &isUTC=false)
 
 Datetime (const std::string &timestamp, const char *format, const bool &isUTC=false)
 
 Datetime (const char *timestamp, const std::string &format, const bool &isUTC=false)
 
 Datetime (const char *timestamp, const char *format, const bool &isUTC=false)
 
 Datetime (const std::string &timestamp, const bool &isUTC=false)
 
 Datetime (const char *timestamp, const bool &isUTC=false)
 
 Datetime (struct tm datetime, const bool &isUTC=false)
 
 Datetime (const time_t &unixTime=0, const bool &isUTC=false)
 
 Datetime (const Datetime &original)
 
 Datetime (const int &year, const int &mon, const int &day, const int &hour, const int &min, const int &sec, const bool &isUTC=false)
 
void setIsUTC (const bool &isUTC)
 
bool isUTC () const
 
struct tm structTm () const
 
std::string str () const
 
std::string str (const std::string &format) const
 
std::string str (const char *format) const
 
std::string datetime () const
 
std::string date () const
 
std::string timesOfday () const
 
int sec () const
 
int minute () const
 
int hour () const
 
int day () const
 
int month () const
 
long year () const
 
long long unixTime () const
 
int daysOfWeek () const
 
std::string timezone () const
 
int isDst () const
 
std::vector< int > toVector () const
 
Datetime operator+ (const long long &right) const
 
Datetime operator+ (const TimeDelta &right) const
 
Datetime operator- (const long long &right) const
 
Datetime operator- (const TimeDelta &right) const
 
Datetimeoperator= (const Datetime &right_t)
 
Datetimeoperator+= (const long long &right)
 
Datetimeoperator+= (const TimeDelta &right)
 
Datetimeoperator-= (const long long &right)
 
Datetimeoperator-= (const TimeDelta &right)
 

Static Public Member Functions

static Datetime now (const bool &isUTC=false)
 
static Datetime minimum (const bool &isUTC=false)
 
static Datetime maximum (const bool &isUTC=false)
 

Detailed Description

Datetime object.

A datetime object handles date and time information.

Constructor & Destructor Documentation

◆ Datetime() [1/5]

EZ::Datetime::Datetime ( const std::string &  timestamp,
const std::string &  format,
const bool &  isUTC = false 
)
inline
Parameters
[in]timestampex: 2021/3/8 0:00:15
[in]formatex: Y/m/d H:M:S
[in]isUTC=falseif true, UTC is set to timezone.
if false, local time is applied.

Timestamp and format must have same delimiters.
ex: auto time = EZ::Datetime("2021/3/8 0:00:15", "%Y/%m/%d %H:%M:%S", true);

◆ Datetime() [2/5]

EZ::Datetime::Datetime ( const std::string &  timestamp,
const bool &  isUTC = false 
)
inline
Parameters
[in]timestampex: 2021/3/8 0:00:15
[in]isUTC=falseif true, UTC is set to timezone.
if false, local time is applied.

Format of timestamp is must be "%Y/%m/%d %H:%M:%S".
ex: auto time = EZ::Datetime("2021/3/8 0:00:15", true);

◆ Datetime() [3/5]

EZ::Datetime::Datetime ( struct tm  datetime,
const bool &  isUTC = false 
)
inline
Parameters
[in]datetimestruct tm
[in]isUTC=falseif true, UTC is set to timezone.
if false, local time is applied.

◆ Datetime() [4/5]

EZ::Datetime::Datetime ( const time_t &  unixTime = 0,
const bool &  isUTC = false 
)
inline
Parameters
[in]unixTime=0
[in]isUTC=falseif true, UTC is set to timezone.
if false, local time is applied.

◆ Datetime() [5/5]

EZ::Datetime::Datetime ( const int &  year,
const int &  mon,
const int &  day,
const int &  hour,
const int &  min,
const int &  sec,
const bool &  isUTC = false 
)
inline
Parameters
[in]year(1970 ~ 2999)
[in]mon(1 ~ 12)
[in]day(1 ~ 31)
[in]hour(0 ~ 23)
[in]min(0 ~ 59)
[in]sec(0 ~ 59)
[in]isUTC=falseif true, UTC is set to timezone.
if false, local time is applied.

ex: 2021/1/1 13:00:00 UTC => EZ::Datetime(2021, 1, 1, 13, 0, 0, true);

Member Function Documentation

◆ date()

std::string EZ::Datetime::date ( ) const
inline

日付を文字列で返却する。フォーマットは固定。
Return the date as a string. Output format is fixed.

Returns
strings of timestamp

ex: 2021/1/1

This function is same as using str("%Y/%m/%d")

◆ datetime()

std::string EZ::Datetime::datetime ( ) const
inline

日時を文字列で返却する。フォーマットは固定。
Return the datetime as a string. Output format is fixed.

ex: 2021/1/1 13:00:00

This function is same as using str("%Y/%m/%d %H:%M:%S")

◆ day()

int EZ::Datetime::day ( ) const
inline

日にちを整数値で返却する
Return the number of day as an integer value.

◆ daysOfWeek()

int EZ::Datetime::daysOfWeek ( ) const
inline

曜日を整数値で返却する
Return the day of the week as an integer value.

Returns
0 => Sunday, 1 => Monday, ..., 6 => Saturday

◆ hour()

int EZ::Datetime::hour ( ) const
inline

時刻値を整数値で返却する
Return the number of hours as an integer value.

◆ isDst()

int EZ::Datetime::isDst ( ) const
inline

サマータイムフラグを返却する
Return the summer time flag.

Returns
number of isDst

0 => Summer time is disabled.
1 => Summer time is enabled.
negative => Depends on your computer.
Specification of return value is same as "struct tm". See also official documentation of struct tm.

◆ isUTC()

bool EZ::Datetime::isUTC ( ) const
inline

インスタンスに設定されたタイムゾーンがUTCならtrueを、現地時間ならfalseを返却する。
Return true if the timezone of the instance is UTC. False if local time.

See also
setIsUtc(const bool& isUTC = false)

◆ maximum()

static Datetime EZ::Datetime::maximum ( const bool &  isUTC = false)
inlinestatic

処理系で表現可能な最新の日付を返す
Returns the newest date that can be handled with this library.

◆ minimum()

static Datetime EZ::Datetime::minimum ( const bool &  isUTC = false)
inlinestatic

処理系で表現可能な最古の日付を返す
Returns the oldest date that can be handled with this library.

◆ minute()

int EZ::Datetime::minute ( ) const
inline

分値を整数値で返却する
Return the number of minutes as an integer value.

◆ month()

int EZ::Datetime::month ( ) const
inline

月数を整数値で返却する
Return the number of month as an integer value.

◆ now()

static Datetime EZ::Datetime::now ( const bool &  isUTC = false)
inlinestatic

コンピュータの現在時刻を取得する
Get the current time of the computer.

Parameters
[in]isUTC=falseif true, UTC is set to timezone.
if false, local time is applied.

ex: auto now = EZ::Datetime::currentTIme(true);

◆ operator+() [1/2]

Datetime EZ::Datetime::operator+ ( const long long &  right) const
inline

ある日付に、指定の秒数を足した後の日付を返却する。
Return the new Datetime object after adding the specified number of seconds to a Datetime object.

◆ operator+() [2/2]

Datetime EZ::Datetime::operator+ ( const TimeDelta right) const
inline

ある日付に、TimeDeltaを足した後の日付を返却する。
Return the new Datetime object after adding the specified TimeDelta object to a Datetime object.

◆ operator+=() [1/2]

Datetime& EZ::Datetime::operator+= ( const long long &  right)
inline

ある日付を、指定の秒数だけ進める
Add the specified number of seconds to a Datetime object.

◆ operator+=() [2/2]

Datetime& EZ::Datetime::operator+= ( const TimeDelta right)
inline

ある日付をTimeDeltaだけ進める
Add the specified TimeDelta object to a Datetime object.

◆ sec()

int EZ::Datetime::sec ( ) const
inline

秒数を整数値で返却する
Return the number of seconds as an integer value.

◆ setIsUTC()

void EZ::Datetime::setIsUTC ( const bool &  isUTC)
inline

表示するタイムゾーンをUTCにするか現地時刻にするか指定する。
Set timezone of instance (UTC or loacl time).
isUTC = false : Express timestamp as localTime.
isUTC = true : Express timestamp as UTC.

◆ str() [1/3]

std::string EZ::Datetime::str ( ) const
inline

タイムスタンプを文字列で返却する。出力文字列はデフォルトのフォーマットで返却される。
Return the timestamp as a string. The output format is default format.

Returns
strings of timestamp
ex: 2021/1/1 13:00:00 UTC

◆ str() [2/3]

std::string EZ::Datetime::str ( const char *  format) const
inline

タイムスタンプを文字列で返却する。出力フォーマットは引数で指定する。
Return the timestamp as a string. Output format is specified by argument.

Parameters
[in]formatstrings with format specifier
ex: format = "%Y/%m/%d_%H:%M:%S" => 2021/1/1_13:00:00

◆ str() [3/3]

std::string EZ::Datetime::str ( const std::string &  format) const
inline

タイムスタンプを文字列で返却する。出力フォーマットは引数で指定する。
Return the timestamp as a string. Output format is specified by argument.

Parameters
[in]formatstrings with format specifier
ex: format = "%Y/%m/%d_%H:%M:%S" => 2021/1/1_13:00:00

◆ structTm()

struct tm EZ::Datetime::structTm ( ) const
inline

タイムスタンプをstruct tmで返却する
Return the timestamp as a "struct tm".

◆ timesOfday()

std::string EZ::Datetime::timesOfday ( ) const
inline

時刻を文字列で返却する。フォーマットは固定。
Return the time as a string. Output format is fixed.

Returns
strings of timestamp

ex: 13:00:00

This function is same as using str("%H:%M:%S")

◆ timezone()

std::string EZ::Datetime::timezone ( ) const
inline

週番号を返却する
Return the week number as an integer value.
タイムゾーンを返却する
Return the timezone of the instance.

unix, mac: UTC, JST, EST, ...etc

Windows: UTC, 90min from UTC, -270 min from UTC, ...etc

◆ toVector()

std::vector<int> EZ::Datetime::toVector ( ) const
inline

{年, 月, 日, 時, 分, 秒} の6つの要素をもつvectorを返却する
Returns a vector with 6 elements {year, month, day, hour, minute, second}.

ex: {2021,1,1,23,59,59}

◆ unixTime()

long long EZ::Datetime::unixTime ( ) const
inline

日時をUnix秒で返却する
Return the datetime in unix seconds.

◆ year()

long EZ::Datetime::year ( ) const
inline

西暦を整数値で返却する
Return the year as an integer value.


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