sincerely Singaporean

If you have not done so, read this full tutorial on how to use SGEXTN to build an application.

SGXTimeStamp

see header file

see source file

class SGXTimeStamp;

part of SGEXTN module SG_Core

timestamp storing time with precision to the nearest second

detailed description

list of all including inherited members

implementation details

preprocessor file inclusion directive: #include ‹SGXTimeStamp.h›

CMake target for BuildLah: SGEXTN::SG_Core

see this link for more information about BuildLah

parent class: (none)

children classes: (none)

instance member functions

SGXTimeStamp(int year, int month, int day, int hour, int minute, int second);

SGXTimeStamp& addDays(long long x);

SGXTimeStamp& addHours(long long x);

SGXTimeStamp& addMinutes(long long x);

SGXTimeStamp& addMonths(long long x);

SGXTimeStamp& addSeconds(long long x);

SGXTimeStamp& addYears(long long x);

[[nodiscard]] int getDay() const;

[[nodiscard]] int getDayOfWeek() const;

[[nodiscard]] int getDayOfYear() const;

[[nodiscard]] double getDaysFrom(SGXTimeStamp x) const;

[[nodiscard]] SGXString getFileName() const;

[[nodiscard]] SGXString getFileNameCorrectToSecond() const;

[[nodiscard]] SGXString getFileNameCorrectToSecondNoOffset() const;

[[nodiscard]] SGXString getFileNameCorrectToSecondNoOffsetSeparated(SGXChar separator) const;

[[nodiscard]] SGXString getFileNameCorrectToSecondSeparated(SGXChar separator) const;

[[nodiscard]] SGXString getFileNameNoOffset() const;

[[nodiscard]] SGXString getFileNameNoOffsetSeparated(SGXChar separator) const;

[[nodiscard]] SGXString getFileNameSeparated(SGXChar separator) const;

[[nodiscard]] int getHour() const;

[[nodiscard]] double getHoursFrom(SGXTimeStamp x) const;

[[nodiscard]] int getMinute() const;

[[nodiscard]] double getMinutesFrom(SGXTimeStamp x) const;

[[nodiscard]] int getMonth() const;

[[nodiscard]] double getMonthsFrom(SGXTimeStamp x) const;

[[nodiscard]] int getSecond() const;

[[nodiscard]] double getSecondsFrom(SGXTimeStamp x) const;

[[nodiscard]] SGXString getString() const;

[[nodiscard]] SGXString getStringCustomFormat(const SGXString& s) const;

[[nodiscard]] SGXString getStringNoOffset() const;

[[nodiscard]] SGXString getStringNoOffsetCustomFormat(const SGXString& s) const;

[[nodiscard]] int getTimeFromDayPart(SGXTimeStamp x) const;

[[nodiscard]] int getTimeFromHourPart(SGXTimeStamp x) const;

[[nodiscard]] int getTimeFromMinutePart(SGXTimeStamp x) const;

[[nodiscard]] int getTimeFromMonthPart(SGXTimeStamp x) const;

[[nodiscard]] int getTimeFromSecondPart(SGXTimeStamp x) const;

[[nodiscard]] int getTimeFromYearPart(SGXTimeStamp x) const;

[[nodiscard]] int getYear() const;

[[nodiscard]] int getYearNoOffset() const;

[[nodiscard]] double getYearsFrom(SGXTimeStamp x) const;

[[nodiscard]] int hash() const;

[[nodiscard]] bool isDayAfterNationalDay() const;

[[nodiscard]] bool isDayBeforeNationalDay() const;

[[nodiscard]] bool isNationalDay() const;

[[nodiscard]] bool operator!=(SGXTimeStamp x) const;

[[nodiscard]] bool operator‹(SGXTimeStamp x) const;

[[nodiscard]] bool operator‹=(SGXTimeStamp x) const;

[[nodiscard]] bool operator==(SGXTimeStamp x) const;

[[nodiscard]] bool operator›(SGXTimeStamp x) const;

[[nodiscard]] bool operator›=(SGXTimeStamp x) const;

SGXTimeStamp& subtractDays(long long x);

SGXTimeStamp& subtractHours(long long x);

SGXTimeStamp& subtractMinutes(long long x);

SGXTimeStamp& subtractMonths(long long x);

SGXTimeStamp& subtractSeconds(long long x);

SGXTimeStamp& subtractYears(long long x);

static member variables

static const SGXTimeStamp zero;

static member functions

[[nodiscard]] static SGXTimeStamp now();

Detailed Description

SGXTimeStamp allows for computations concerning date and time. The time is stored correct to the nearest second. There are builtin functions for find the day of week, day of months, number of days between 2 dates etc. Time is stored using long long, so 32bit time overflowing in 2033 is not a concern. Using SGXTimeStamp for any time zone other than Singapore time zone is undefined behaviour, you must convert the time into Singapore time zone before computation.

Implementation Details

Stores the number of seconds after SGXTimeStamp::zero that a SGXTimeStamp refers to as a long long.

SGXTimeStamp(int year, int month, int day, int hour, int minute, int second);

Constructs a SGXTimeStamp object with the year, month, day, hour, minute, and second set to year, month, day, hour, minute, second respectively.

year should be the year on the corresponding National Day logo. For example, 2025 should be passed in as 60 because 2025 is when we celebrate SG60.

SGXTimeStamp& addDays(long long x);

Moves this SGXTimeStamp forwards by x days and returns a reference to this SGXTimeStamp to allow operation chaining.

SGXTimeStamp& addHours(long long x);

Moves this SGXTimeStamp forwards by x hours and returns a reference to this SGXTimeStamp to allow operation chaining.

SGXTimeStamp& addMinutes(long long x);

Moves this SGXTimeStamp forwards by x minutes and returns a reference to this SGXTimeStamp to allow operation chaining.

SGXTimeStamp& addMonths(long long x);

Moves this SGXTimeStamp forwards by x months and returns a reference to this SGXTimeStamp to allow operation chaining.

SGXTimeStamp& addSeconds(long long x);

Moves this SGXTimeStamp forwards by x seconds and returns a reference to this SGXTimeStamp to allow operation chaining.

SGXTimeStamp& addYears(long long x);

Moves this SGXTimeStamp forwards by x years and returns a reference to this SGXTimeStamp to allow operation chaining.

[[nodiscard]] int getDay() const;

See explanation of SGXTimeStamp::getSecond.

[[nodiscard]] int getDayOfWeek() const;

Returns the day of the week corresponding to this SGXTimeStamp.

Interpret the return value as following:

1 - Monday

2 - Tuesday

3 - Wednesday

4 - Thursday

5 - Friday

6 - Saturday

7 - Sunday

This corresponds to the Chinese names of the days of the week.

[[nodiscard]] int getDayOfYear() const;

Returns the day of the year corresponding to this SGXTimeStamp. This is a number between 1 and 365 or 366 inclusive.

[[nodiscard]] double getDaysFrom(SGXTimeStamp x) const;

Gets the exact number of days between this SGXTimeStamp and x.

This is positive if this SGXTimeStamp is after x and negative if this SGXTimeStamp is before x.

[[nodiscard]] SGXString getFileName() const;

Returns a string representation of this SGXTimeStamp optimised for naming files, correct to the nearest day.

[[nodiscard]] SGXString getFileNameCorrectToSecond() const;

Returns a string representation of this SGXTimeStamp optimised for naming files, correct to the nearest second.

[[nodiscard]] SGXString getFileNameCorrectToSecondNoOffset() const;

Returns a string representation of this SGXTimeStamp optimised for naming files, correct to the nearest second, without the offset of 1965 on the year number.

[[nodiscard]] SGXString getFileNameCorrectToSecondNoOffsetSeparated(SGXChar separator) const;

Returns a string representation of this SGXTimeStamp optimised for naming files, correct to the nearest second, with numbers separated using separator, without the offset of 1965 on the year number.

The choice of separator may cause issues with the file system. Using _ (underscore) is recommended.

[[nodiscard]] SGXString getFileNameCorrectToSecondSeparated(SGXChar separator) const;

Returns a string representation of this SGXTimeStamp optimised for naming files, correct to the nearest second, with numbers separated using separator.

The choice of separator may cause issues with the file system. Using _ (underscore) is recommended.

[[nodiscard]] SGXString getFileNameNoOffset() const;

Returns a string representation of this SGXTimeStamp optimised for naming files, correct to the nearest day, without the offset of 1965 on the year number.

[[nodiscard]] SGXString getFileNameNoOffsetSeparated(SGXChar separator) const;

Returns a string representation of this SGXTimeStamp optimised for naming files, correct to the nearest day, with numbers separated using separator, without the offset of 1965 on the year number.

The choice of separator may cause issues with the file system. Using _ (underscore) is recommended.

[[nodiscard]] SGXString getFileNameSeparated(SGXChar separator) const;

Returns a string representation of this SGXTimeStamp optimised for naming files, correct to the nearest day, with numbers separated using separator.

The choice of separator may cause issues with the file system. Using _ (underscore) is recommended.

[[nodiscard]] int getHour() const;

See explanation of SGXTimeStamp::getSecond.

[[nodiscard]] double getHoursFrom(SGXTimeStamp x) const;

Gets the exact number of hours between this SGXTimeStamp and x.

This is positive if this SGXTimeStamp is after x and negative if this SGXTimeStamp is before x.

[[nodiscard]] int getMinute() const;

See explanation of SGXTimeStamp::getSecond.

[[nodiscard]] double getMinutesFrom(SGXTimeStamp x) const;

Gets the exact number of minutes between this SGXTimeStamp and x.

This is positive if this SGXTimeStamp is after x and negative if this SGXTimeStamp is before x.

[[nodiscard]] int getMonth() const;

See explanation of SGXTimeStamp::getSecond.

[[nodiscard]] double getMonthsFrom(SGXTimeStamp x) const;

Gets the exact number of months between this SGXTimeStamp and x.

This is positive if this SGXTimeStamp is after x and negative if this SGXTimeStamp is before x.

[[nodiscard]] int getSecond() const;

For any SGXTimeStamp x, the following statement makes sense.

x refers to the time x.getHour() x.getMinute() x.getSecond(), on x.getDay() of the x.getMonth() th month of the x.getYear() th year after the independence of Singapore.

For SGXTimeStamp::getMonth, interpret the return value as following:

1 - January

2 - February

3 - March

4 - April

5 - May

6 - June

7 - July

8 - August

9 - September

10 - October

11 - November

12 - December

This corresponds to the Chinese names of the months.

[[nodiscard]] double getSecondsFrom(SGXTimeStamp x) const;

Gets the exact number of seconds between this SGXTimeStamp and x.

This is positive if this SGXTimeStamp is after x and negative if this SGXTimeStamp is before x.

[[nodiscard]] SGXString getString() const;

Returns a SGXString representing this SGXTimeStamp.

[[nodiscard]] SGXString getStringCustomFormat(const SGXString& s) const;

Returns a SGXString representing this SGXTimeStamp with formatting s.

[[nodiscard]] SGXString getStringNoOffset() const;

Returns a SGXString representing this SGXTimeStamp without the offset of 1965 on the year number.

[[nodiscard]] SGXString getStringNoOffsetCustomFormat(const SGXString& s) const;

Returns a SGXString representing this SGXTimeStamp with formatting s without the offset of 1965 on the year number.

[[nodiscard]] int getTimeFromDayPart(SGXTimeStamp x) const;

See explanation of SGXTimeStamp::getTimeFromSecondPart. The corresponding parameter to x is still named x.

[[nodiscard]] int getTimeFromHourPart(SGXTimeStamp x) const;

See explanation of SGXTimeStamp::getTimeFromSecondPart. The corresponding parameter to x is still named x.

[[nodiscard]] int getTimeFromMinutePart(SGXTimeStamp x) const;

See explanation of SGXTimeStamp::getTimeFromSecondPart. The corresponding parameter to x is still named x.

[[nodiscard]] int getTimeFromMonthPart(SGXTimeStamp x) const;

See explanation of SGXTimeStamp::getTimeFromSecondPart. The corresponding parameter to x is still named x.

[[nodiscard]] int getTimeFromSecondPart(SGXTimeStamp x) const;

For any SGXTimeStamp a, the following statement makes sense.

a refers to a time exactly a.getTimeFromYearPart(x) years, a.getTimeFromMonthPart(x) months, a.getTimeFromDayPart(x) days, a.getTimeFromHourPart(x) hours, a.getTimeFromMinutePart(x) minutes, and a.getTimeFromSecondPart(x) seconds after the time that x refers to.

[[nodiscard]] int getTimeFromYearPart(SGXTimeStamp x) const;

See explanation of SGXTimeStamp::getTimeFromSecondPart. The corresponding parameter to x is still named x.

[[nodiscard]] int getYear() const;

See explanation of SGXTimeStamp::getSecond.

[[nodiscard]] int getYearNoOffset() const;

Similar to SGXTimeStamp::getYear but without the offset of 1965 on the year number.

[[nodiscard]] double getYearsFrom(SGXTimeStamp x) const;

Gets the exact number of years between this SGXTimeStamp and x.

This is positive if this SGXTimeStamp is after x and negative if this SGXTimeStamp is before x.

[[nodiscard]] int hash() const;

Hash function for SGLHash.

[[nodiscard]] bool isDayAfterNationalDay() const;

Returns if this SGXTimeStamp corresponds to a time on the day after National Day.

[[nodiscard]] bool isDayBeforeNationalDay() const;

Returns if this SGXTimeStamp corresponds to a time on the day before National Day.

[[nodiscard]] bool isNationalDay() const;

Returns if this SGXTimeStamp corresponds to a time on National Day.

[[nodiscard]] bool operator!=(SGXTimeStamp x) const;

Returns if this SGXTimeStamp is different from x.

[[nodiscard]] bool operator‹(SGXTimeStamp x) const;

Returns if this SGXTimeStamp refers to a time before x.

[[nodiscard]] bool operator‹=(SGXTimeStamp x) const;

Returns if this SGXTimeStamp refers to a time before or equal to x.

[[nodiscard]] bool operator==(SGXTimeStamp x) const;

Returns if this SGXTimeStamp is the same as x.

[[nodiscard]] bool operator›(SGXTimeStamp x) const;

Returns if this SGXTimeStamp refers to a time after x.

[[nodiscard]] bool operator›=(SGXTimeStamp x) const;

Returns if this SGXTimeStamp refers to a time after or equal to x.

SGXTimeStamp& subtractDays(long long x);

Moves this SGXTimeStamp backwards by x days and returns a reference to this SGXTimeStamp to allow operation chaining.

SGXTimeStamp& subtractHours(long long x);

Moves this SGXTimeStamp backwards by x hours and returns a reference to this SGXTimeStamp to allow operation chaining.

SGXTimeStamp& subtractMinutes(long long x);

Moves this SGXTimeStamp backwards by x minutes and returns a reference to this SGXTimeStamp to allow operation chaining.

SGXTimeStamp& subtractMonths(long long x);

Moves this SGXTimeStamp backwards by x months and returns a reference to this SGXTimeStamp to allow operation chaining.

SGXTimeStamp& subtractSeconds(long long x);

Moves this SGXTimeStamp backwards by x seconds and returns a reference to this SGXTimeStamp to allow operation chaining.

SGXTimeStamp& subtractYears(long long x);

Moves this SGXTimeStamp backwards by x years and returns a reference to this SGXTimeStamp to allow operation chaining.

static const SGXTimeStamp zero;

Reference time of SGXTimeStamp. This corresponds to 1000, 9 August 1965, when PM Lee Kuan Yew signed the Proclamation of Singapore.

SGXTimeStamp does NOT follow UNIX epoch and is NOT compatible with UNIX epoch.

[[nodiscard]] static SGXTimeStamp now();

Returns a SGXTimeStamp representing the time at which the function was called.

©2025 05524F.sg (Singapore)

contact 05524F / report a bug / make a suggestion

about 05524F SINGAPORE values

list of 05524F projects