Created
December 23, 2017 15:20
-
-
Save YashasSamaga/56c79e90cd21637619955d1d414b7c18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
** PAWN Library Extension (PLE) | |
** | |
** Chrono | |
** Time library | |
** | |
** This file is part of PAWN Library Extension. | |
** | |
** This library is free software: you can redistribute it and/or modify | |
** it under the terms of the GNU General Public License as published by | |
** the Free Software Foundation, either version 3 of the License, or | |
** (at your option) any later version. | |
** | |
** This library is distributed in the hope that it will be useful, | |
** but WITHOUT ANY WARRANTY; without even the implied warranty of | |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
** GNU General Public License for more details. | |
** | |
** You should have received a copy of the GNU General Public License | |
** along with this library. If not, see <http://www.gnu.org/licenses/>. | |
** | |
** Copyright (C) 2016-2018 Yashas Samaga | |
*/ | |
#if defined PLE_CHRONO_INCLUDED | |
#endinput | |
#endif | |
#define PLE_CHRONO_INCLUDED | |
/* dependencies */ | |
#include <PLE/config> | |
/* | |
** system_clock | |
** This clock directly maps to the operating system's clock. | |
*/ | |
#define system_clock:: syc_ | |
/* system_clock::now() returns the number of seconds from an implementation | |
defined epoch. Therefore, timestamp_t is sort of an alias for seconds_t */ | |
native timestamp_t:system_clock::now(); | |
/* | |
** steady_clock | |
** This represents a monotonic clock indepdent of the system clock. The time | |
** points of this clock is gaurnteed to never decrease unless there is an | |
** overflow. | |
** | |
** The epoch for this clock is the time of start of the "server process". | |
*/ | |
#define steady_clock:: stc_ | |
/* returns the number of seconds since the epoch */ | |
native seconds_t:steady_clock::now(); | |
/* returns positive offsets from current second | |
returns 0 always if the time period is not supported */ | |
native milliseconds_t:steady_clock::milliseconds(); /* microseconds in range [0, 1000)*/ | |
native microseconds_t:steady_clock::microseconds(); /* microseconds in range [0, 1000000)*/ | |
native nanoseconds_t:steady_clock::nanoseconds(); /* nanoseconds in range [0, 1000000000)*/ | |
/* | |
** datetime structure (tm_t) | |
** timestamps can be broken down into human readable structure | |
*/ | |
/* broken down structure for time points */ | |
enum tm_t | |
{ | |
second = 0, | |
minute = 1, | |
hour = 2, | |
day = 3, | |
month = 4, | |
year = 5, | |
wday = 6, //0-6 | |
yday = 7, //0-365 | |
isdst = 8 //true if daylight saving time is in effect | |
} | |
/* builds the datetime structure representing UTC from the timestamp */ | |
native to_universal(timestamp_t:ts, tm[tm_t]); | |
/* builds the datetime structure representing local time from the timestamp */ | |
native to_local(timestamp_t:ts, tm[tm_t]); | |
/* reduces a local datetime structure to timestamp */ | |
native timestamp_t:to_timestamp(tm[tm_t]); | |
/* | |
** datetime strings | |
** tm_t structures can be convereted into strings | |
*/ | |
/* format: Www Mmm dd hh:mm:ss yyyy\n */ | |
native asctime(tm[tm_t], result[], size_res = sizeof(result)); | |
/* TBD */ | |
native strftime(tm[tm_t], const format[], result[], size_res = sizeof(result)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment