Added three tests, added license headers
This commit is contained in:
parent
d798c5e56a
commit
ea728b2487
10 changed files with 254 additions and 3 deletions
34
datetime.c
34
datetime.c
|
@ -1,3 +1,35 @@
|
|||
/* _,.---._ .-._ .--.-. ,--.--------.
|
||||
* _,..---._ ,-.' , - `. /==/ \ .-._/==/ //==/, - , -\
|
||||
* /==/, - \ /==/_, , - \|==|, \/ /, |==\ -\\==\.-. - ,-./
|
||||
* |==| _ _\==| .=. |==|- \| | \==\- \`--`\==\- \
|
||||
* |==| .=. |==|_ : ;=: - |==| , | -| `--`-' \==\_ \
|
||||
* |==|,| | -|==| , '=' |==| - _ | |==|- |
|
||||
* |==| '=' /\==\ - ,_ /|==| /\ , | |==|, |
|
||||
* |==|-, _`/ '.='. - .' /==/, | |- | /==/ -/
|
||||
* `-.`.____.' `--`--'' `--`./ `--` `--`--`
|
||||
* _ __ ,---. .-._ .=-.-. _,.----.
|
||||
* .-`.' ,`..--.' \ /==/ \ .-._ /==/_ /.' .' - \
|
||||
* /==/, - \==\-/\ \ |==|, \/ /, /==|, |/==/ , ,-'
|
||||
* |==| _ .=. /==/-|_\ | |==|- \| ||==| ||==|- | .
|
||||
* |==| , '=',\==\, - \ |==| , | -||==|- ||==|_ `-' \
|
||||
* |==|- '..'/==/ - ,| |==| - _ ||==| ,||==| _ , |
|
||||
* |==|, | /==/- /\ - \|==| /\ , ||==|- |\==\. /
|
||||
* /==/ - | \==\ _.\=\.-'/==/, | |- |/==/. / `-.`.___.-'
|
||||
* `--`---' `--` `--`./ `--``--`-`
|
||||
*
|
||||
* @(#)Copyright (c) 2024, Nathan D. Fisher.
|
||||
*
|
||||
* This is free software. It comes with NO WARRANTY.
|
||||
* Permission to use, modify and distribute this source code
|
||||
* is granted subject to the following conditions.
|
||||
* 1/ that the above copyright notice and this notice
|
||||
* are preserved in all copies and that due credit be given
|
||||
* to the author.
|
||||
* 2/ that any changes to this code are clearly commented
|
||||
* as such so that the author does not get blamed for bugs
|
||||
* other than his own.
|
||||
*/
|
||||
|
||||
#include "epoch.h"
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
@ -40,7 +72,7 @@ int64_t dateTimeGetTimestamp(DateTime *self) {
|
|||
return seconds;
|
||||
}
|
||||
|
||||
void dateTimeGetTimeval(DateTime *self, struct timespec * ts) {
|
||||
void dateTimeGetTimespec(DateTime *self, struct timespec * ts) {
|
||||
ts->tv_nsec = self->nanoseconds;
|
||||
ts->tv_sec = (time_t)dateTimeGetTimestamp(self);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,40 @@
|
|||
/* _,.---._ .-._ .--.-. ,--.--------.
|
||||
* _,..---._ ,-.' , - `. /==/ \ .-._/==/ //==/, - , -\
|
||||
* /==/, - \ /==/_, , - \|==|, \/ /, |==\ -\\==\.-. - ,-./
|
||||
* |==| _ _\==| .=. |==|- \| | \==\- \`--`\==\- \
|
||||
* |==| .=. |==|_ : ;=: - |==| , | -| `--`-' \==\_ \
|
||||
* |==|,| | -|==| , '=' |==| - _ | |==|- |
|
||||
* |==| '=' /\==\ - ,_ /|==| /\ , | |==|, |
|
||||
* |==|-, _`/ '.='. - .' /==/, | |- | /==/ -/
|
||||
* `-.`.____.' `--`--'' `--`./ `--` `--`--`
|
||||
* _ __ ,---. .-._ .=-.-. _,.----.
|
||||
* .-`.' ,`..--.' \ /==/ \ .-._ /==/_ /.' .' - \
|
||||
* /==/, - \==\-/\ \ |==|, \/ /, /==|, |/==/ , ,-'
|
||||
* |==| _ .=. /==/-|_\ | |==|- \| ||==| ||==|- | .
|
||||
* |==| , '=',\==\, - \ |==| , | -||==|- ||==|_ `-' \
|
||||
* |==|- '..'/==/ - ,| |==| - _ ||==| ,||==| _ , |
|
||||
* |==|, | /==/- /\ - \|==| /\ , ||==|- |\==\. /
|
||||
* /==/ - | \==\ _.\=\.-'/==/, | |- |/==/. / `-.`.___.-'
|
||||
* `--`---' `--` `--`./ `--``--`-`
|
||||
*
|
||||
* @(#)Copyright (c) 2024, Nathan D. Fisher.
|
||||
*
|
||||
* This is free software. It comes with NO WARRANTY.
|
||||
* Permission to use, modify and distribute this source code
|
||||
* is granted subject to the following conditions.
|
||||
* 1/ that the above copyright notice and this notice
|
||||
* are preserved in all copies and that due credit be given
|
||||
* to the author.
|
||||
* 2/ that any changes to this code are clearly commented
|
||||
* as such so that the author does not get blamed for bugs
|
||||
* other than his own.
|
||||
*/
|
||||
|
||||
#ifndef LIBEPOCH_H
|
||||
#define LIBEPOCH_H 1
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#define SECONDS_PER_MINUTE 60
|
||||
#define SECONDS_PER_HOUR 60 * 60
|
||||
|
@ -110,5 +143,6 @@ int64_t timezoneAsSeconds(TimeZone *tz);
|
|||
int32_t dateTimeGetYear(DateTime *self);
|
||||
int64_t dateTimeGetTimestampNaive(DateTime *self);
|
||||
int64_t dateTimeGetTimestamp(DateTime *self);
|
||||
void dateTimeGetTimespec(DateTime *self, struct timespec *ts);
|
||||
|
||||
#endif // !LIBEPOCH_H
|
||||
|
|
32
month.c
32
month.c
|
@ -1,3 +1,35 @@
|
|||
/* _,.---._ .-._ .--.-. ,--.--------.
|
||||
* _,..---._ ,-.' , - `. /==/ \ .-._/==/ //==/, - , -\
|
||||
* /==/, - \ /==/_, , - \|==|, \/ /, |==\ -\\==\.-. - ,-./
|
||||
* |==| _ _\==| .=. |==|- \| | \==\- \`--`\==\- \
|
||||
* |==| .=. |==|_ : ;=: - |==| , | -| `--`-' \==\_ \
|
||||
* |==|,| | -|==| , '=' |==| - _ | |==|- |
|
||||
* |==| '=' /\==\ - ,_ /|==| /\ , | |==|, |
|
||||
* |==|-, _`/ '.='. - .' /==/, | |- | /==/ -/
|
||||
* `-.`.____.' `--`--'' `--`./ `--` `--`--`
|
||||
* _ __ ,---. .-._ .=-.-. _,.----.
|
||||
* .-`.' ,`..--.' \ /==/ \ .-._ /==/_ /.' .' - \
|
||||
* /==/, - \==\-/\ \ |==|, \/ /, /==|, |/==/ , ,-'
|
||||
* |==| _ .=. /==/-|_\ | |==|- \| ||==| ||==|- | .
|
||||
* |==| , '=',\==\, - \ |==| , | -||==|- ||==|_ `-' \
|
||||
* |==|- '..'/==/ - ,| |==| - _ ||==| ,||==| _ , |
|
||||
* |==|, | /==/- /\ - \|==| /\ , ||==|- |\==\. /
|
||||
* /==/ - | \==\ _.\=\.-'/==/, | |- |/==/. / `-.`.___.-'
|
||||
* `--`---' `--` `--`./ `--``--`-`
|
||||
*
|
||||
* @(#)Copyright (c) 2024, Nathan D. Fisher.
|
||||
*
|
||||
* This is free software. It comes with NO WARRANTY.
|
||||
* Permission to use, modify and distribute this source code
|
||||
* is granted subject to the following conditions.
|
||||
* 1/ that the above copyright notice and this notice
|
||||
* are preserved in all copies and that due credit be given
|
||||
* to the author.
|
||||
* 2/ that any changes to this code are clearly commented
|
||||
* as such so that the author does not get blamed for bugs
|
||||
* other than his own.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h> // NULL
|
||||
#include <string.h> // memcmp
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
# /==/ - | \==\ _.\=\.-'/==/, | |- |/==/. / `-.`.___.-'
|
||||
# `--`---' `--` `--`./ `--``--`-`
|
||||
#
|
||||
# @(#)Copyright (c) 2023, Nathan D. Fisher.
|
||||
# @(#)Copyright (c) 2024, Nathan D. Fisher.
|
||||
#
|
||||
# This is free software. It comes with NO WARRANTY.
|
||||
# Permission to use, modify and distribute this source code
|
||||
|
@ -36,7 +36,9 @@ CFLAGS += -I../include
|
|||
LDLIBS += ../libepoch.a
|
||||
LDLIBS += $(LIBS)
|
||||
|
||||
tests += extract_hardlink_node
|
||||
tests += dt2ts
|
||||
tests += dt2timespec
|
||||
tests += parsemonth
|
||||
|
||||
total != echo $(tests) | wc -w | awk '{ print $$1 }'
|
||||
|
||||
|
|
23
test/dt2timespec.c
Normal file
23
test/dt2timespec.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include "epoch.h"
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
DateTime dt;
|
||||
struct timespec ts;
|
||||
|
||||
int main() {
|
||||
dt.zone.tag = UTC;
|
||||
yearNew(&dt.year, 2024);
|
||||
dt.month = February;
|
||||
dt.day = 6;
|
||||
dt.hour = 9;
|
||||
dt.minute = 28;
|
||||
dt.second = 42;
|
||||
dt.nanoseconds = 42;
|
||||
dateTimeGetTimespec(&dt, &ts);
|
||||
assert(ts.tv_sec == 1707211722);
|
||||
assert(ts.tv_nsec == 42);
|
||||
|
||||
return 0;
|
||||
}
|
21
test/dt2ts.c
Normal file
21
test/dt2ts.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "epoch.h"
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
DateTime dt;
|
||||
int64_t ts;
|
||||
|
||||
int main() {
|
||||
dt.zone.tag = UTC;
|
||||
yearNew(&dt.year, 2024);
|
||||
dt.month = February;
|
||||
dt.day = 6;
|
||||
dt.hour = 9;
|
||||
dt.minute = 28;
|
||||
dt.second = 42;
|
||||
dt.nanoseconds = 42;
|
||||
ts = dateTimeGetTimestamp(&dt);
|
||||
assert(ts == 1707211722);
|
||||
|
||||
return 0;
|
||||
}
|
11
test/parsemonth.c
Normal file
11
test/parsemonth.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "epoch.h"
|
||||
#include <assert.h>
|
||||
|
||||
int main() {
|
||||
Month m = parseMonth("February");
|
||||
assert(m == February);
|
||||
m = parseMonth("nov");
|
||||
assert(m == November);
|
||||
m = parseMonth("MARCH");
|
||||
assert(m == March);
|
||||
}
|
32
weekday.c
32
weekday.c
|
@ -1,3 +1,35 @@
|
|||
/* _,.---._ .-._ .--.-. ,--.--------.
|
||||
* _,..---._ ,-.' , - `. /==/ \ .-._/==/ //==/, - , -\
|
||||
* /==/, - \ /==/_, , - \|==|, \/ /, |==\ -\\==\.-. - ,-./
|
||||
* |==| _ _\==| .=. |==|- \| | \==\- \`--`\==\- \
|
||||
* |==| .=. |==|_ : ;=: - |==| , | -| `--`-' \==\_ \
|
||||
* |==|,| | -|==| , '=' |==| - _ | |==|- |
|
||||
* |==| '=' /\==\ - ,_ /|==| /\ , | |==|, |
|
||||
* |==|-, _`/ '.='. - .' /==/, | |- | /==/ -/
|
||||
* `-.`.____.' `--`--'' `--`./ `--` `--`--`
|
||||
* _ __ ,---. .-._ .=-.-. _,.----.
|
||||
* .-`.' ,`..--.' \ /==/ \ .-._ /==/_ /.' .' - \
|
||||
* /==/, - \==\-/\ \ |==|, \/ /, /==|, |/==/ , ,-'
|
||||
* |==| _ .=. /==/-|_\ | |==|- \| ||==| ||==|- | .
|
||||
* |==| , '=',\==\, - \ |==| , | -||==|- ||==|_ `-' \
|
||||
* |==|- '..'/==/ - ,| |==| - _ ||==| ,||==| _ , |
|
||||
* |==|, | /==/- /\ - \|==| /\ , ||==|- |\==\. /
|
||||
* /==/ - | \==\ _.\=\.-'/==/, | |- |/==/. / `-.`.___.-'
|
||||
* `--`---' `--` `--`./ `--``--`-`
|
||||
*
|
||||
* @(#)Copyright (c) 2024, Nathan D. Fisher.
|
||||
*
|
||||
* This is free software. It comes with NO WARRANTY.
|
||||
* Permission to use, modify and distribute this source code
|
||||
* is granted subject to the following conditions.
|
||||
* 1/ that the above copyright notice and this notice
|
||||
* are preserved in all copies and that due credit be given
|
||||
* to the author.
|
||||
* 2/ that any changes to this code are clearly commented
|
||||
* as such so that the author does not get blamed for bugs
|
||||
* other than his own.
|
||||
*/
|
||||
|
||||
#include "epoch.h"
|
||||
#include <strings.h>
|
||||
|
||||
|
|
32
year.c
32
year.c
|
@ -1,3 +1,35 @@
|
|||
/* _,.---._ .-._ .--.-. ,--.--------.
|
||||
* _,..---._ ,-.' , - `. /==/ \ .-._/==/ //==/, - , -\
|
||||
* /==/, - \ /==/_, , - \|==|, \/ /, |==\ -\\==\.-. - ,-./
|
||||
* |==| _ _\==| .=. |==|- \| | \==\- \`--`\==\- \
|
||||
* |==| .=. |==|_ : ;=: - |==| , | -| `--`-' \==\_ \
|
||||
* |==|,| | -|==| , '=' |==| - _ | |==|- |
|
||||
* |==| '=' /\==\ - ,_ /|==| /\ , | |==|, |
|
||||
* |==|-, _`/ '.='. - .' /==/, | |- | /==/ -/
|
||||
* `-.`.____.' `--`--'' `--`./ `--` `--`--`
|
||||
* _ __ ,---. .-._ .=-.-. _,.----.
|
||||
* .-`.' ,`..--.' \ /==/ \ .-._ /==/_ /.' .' - \
|
||||
* /==/, - \==\-/\ \ |==|, \/ /, /==|, |/==/ , ,-'
|
||||
* |==| _ .=. /==/-|_\ | |==|- \| ||==| ||==|- | .
|
||||
* |==| , '=',\==\, - \ |==| , | -||==|- ||==|_ `-' \
|
||||
* |==|- '..'/==/ - ,| |==| - _ ||==| ,||==| _ , |
|
||||
* |==|, | /==/- /\ - \|==| /\ , ||==|- |\==\. /
|
||||
* /==/ - | \==\ _.\=\.-'/==/, | |- |/==/. / `-.`.___.-'
|
||||
* `--`---' `--` `--`./ `--``--`-`
|
||||
*
|
||||
* @(#)Copyright (c) 2024, Nathan D. Fisher.
|
||||
*
|
||||
* This is free software. It comes with NO WARRANTY.
|
||||
* Permission to use, modify and distribute this source code
|
||||
* is granted subject to the following conditions.
|
||||
* 1/ that the above copyright notice and this notice
|
||||
* are preserved in all copies and that due credit be given
|
||||
* to the author.
|
||||
* 2/ that any changes to this code are clearly commented
|
||||
* as such so that the author does not get blamed for bugs
|
||||
* other than his own.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "epoch.h"
|
||||
|
||||
|
|
32
zone.c
32
zone.c
|
@ -1,3 +1,35 @@
|
|||
/* _,.---._ .-._ .--.-. ,--.--------.
|
||||
* _,..---._ ,-.' , - `. /==/ \ .-._/==/ //==/, - , -\
|
||||
* /==/, - \ /==/_, , - \|==|, \/ /, |==\ -\\==\.-. - ,-./
|
||||
* |==| _ _\==| .=. |==|- \| | \==\- \`--`\==\- \
|
||||
* |==| .=. |==|_ : ;=: - |==| , | -| `--`-' \==\_ \
|
||||
* |==|,| | -|==| , '=' |==| - _ | |==|- |
|
||||
* |==| '=' /\==\ - ,_ /|==| /\ , | |==|, |
|
||||
* |==|-, _`/ '.='. - .' /==/, | |- | /==/ -/
|
||||
* `-.`.____.' `--`--'' `--`./ `--` `--`--`
|
||||
* _ __ ,---. .-._ .=-.-. _,.----.
|
||||
* .-`.' ,`..--.' \ /==/ \ .-._ /==/_ /.' .' - \
|
||||
* /==/, - \==\-/\ \ |==|, \/ /, /==|, |/==/ , ,-'
|
||||
* |==| _ .=. /==/-|_\ | |==|- \| ||==| ||==|- | .
|
||||
* |==| , '=',\==\, - \ |==| , | -||==|- ||==|_ `-' \
|
||||
* |==|- '..'/==/ - ,| |==| - _ ||==| ,||==| _ , |
|
||||
* |==|, | /==/- /\ - \|==| /\ , ||==|- |\==\. /
|
||||
* /==/ - | \==\ _.\=\.-'/==/, | |- |/==/. / `-.`.___.-'
|
||||
* `--`---' `--` `--`./ `--``--`-`
|
||||
*
|
||||
* @(#)Copyright (c) 2024, Nathan D. Fisher.
|
||||
*
|
||||
* This is free software. It comes with NO WARRANTY.
|
||||
* Permission to use, modify and distribute this source code
|
||||
* is granted subject to the following conditions.
|
||||
* 1/ that the above copyright notice and this notice
|
||||
* are preserved in all copies and that due credit be given
|
||||
* to the author.
|
||||
* 2/ that any changes to this code are clearly commented
|
||||
* as such so that the author does not get blamed for bugs
|
||||
* other than his own.
|
||||
*/
|
||||
|
||||
#include "epoch.h"
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
|
Loading…
Add table
Reference in a new issue