From ea728b24873fdc5628125f51fce41a308a61b201 Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Tue, 6 Feb 2024 10:01:26 -0500 Subject: [PATCH] Added three tests, added license headers --- datetime.c | 34 +++++++++++++++++++++++++++++++++- include/epoch.h | 34 ++++++++++++++++++++++++++++++++++ month.c | 32 ++++++++++++++++++++++++++++++++ test/Makefile | 6 ++++-- test/dt2timespec.c | 23 +++++++++++++++++++++++ test/dt2ts.c | 21 +++++++++++++++++++++ test/parsemonth.c | 11 +++++++++++ weekday.c | 32 ++++++++++++++++++++++++++++++++ year.c | 32 ++++++++++++++++++++++++++++++++ zone.c | 32 ++++++++++++++++++++++++++++++++ 10 files changed, 254 insertions(+), 3 deletions(-) create mode 100644 test/dt2timespec.c create mode 100644 test/dt2ts.c create mode 100644 test/parsemonth.c diff --git a/datetime.c b/datetime.c index b8a3472..a68db30 100644 --- a/datetime.c +++ b/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 #include @@ -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); } diff --git a/include/epoch.h b/include/epoch.h index 3d44757..614deaa 100644 --- a/include/epoch.h +++ b/include/epoch.h @@ -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 +#include #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 diff --git a/month.c b/month.c index d28fa0a..67c5a56 100644 --- a/month.c +++ b/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 #include // NULL #include // memcmp diff --git a/test/Makefile b/test/Makefile index 0c22812..1d99955 100644 --- a/test/Makefile +++ b/test/Makefile @@ -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 }' diff --git a/test/dt2timespec.c b/test/dt2timespec.c new file mode 100644 index 0000000..2de29c9 --- /dev/null +++ b/test/dt2timespec.c @@ -0,0 +1,23 @@ +#include "epoch.h" +#include +#include +#include + +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; +} diff --git a/test/dt2ts.c b/test/dt2ts.c new file mode 100644 index 0000000..c064bd9 --- /dev/null +++ b/test/dt2ts.c @@ -0,0 +1,21 @@ +#include "epoch.h" +#include +#include + +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; +} diff --git a/test/parsemonth.c b/test/parsemonth.c new file mode 100644 index 0000000..0bb1fae --- /dev/null +++ b/test/parsemonth.c @@ -0,0 +1,11 @@ +#include "epoch.h" +#include + +int main() { + Month m = parseMonth("February"); + assert(m == February); + m = parseMonth("nov"); + assert(m == November); + m = parseMonth("MARCH"); + assert(m == March); +} diff --git a/weekday.c b/weekday.c index abed36a..093986f 100644 --- a/weekday.c +++ b/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 diff --git a/year.c b/year.c index 63b1949..af864c9 100644 --- a/year.c +++ b/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 #include "epoch.h" diff --git a/zone.c b/zone.c index 1873241..0e00744 100644 --- a/zone.c +++ b/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 #include