Formatting and style

This commit is contained in:
Nathan Fisher 2024-02-11 19:14:28 -05:00
parent 0003f3678e
commit d3f4aa04f3
3 changed files with 63 additions and 61 deletions

View file

@ -117,35 +117,37 @@ typedef enum {
NanoSecondPrecision, NanoSecondPrecision,
} datetimePrecision; } datetimePrecision;
void yearNew(Year *year, int32_t inner); void yearNew (Year *self, int32_t inner);
uint16_t yearGetDays(Year *year); uint16_t yearGetDays (Year *self);
int64_t yearGetSeconds(Year *year); int64_t yearGetSeconds (Year *self);
int32_t yearGetInner(Year *year); int32_t yearGetInner (Year *self);
void yearIncrement(Year *year); void yearIncrement (Year *self);
void yearDecrement(Year *year); void yearDecrement (Year *self);
uint8_t monthGetDays(Month month, Year *year); uint8_t monthGetDays (Month self, Year *year);
uint32_t monthGetSeconds(Month month, Year *year); uint32_t monthGetSeconds (Month self, Year *year);
int monthIncrement(Month *month); int monthIncrement (Month *self);
int monthDecrement(Month *month); int monthDecrement (Month *self);
const char* monthName(Month month); const char* monthName (Month self);
const char* monthAbbr(Month month); const char* monthAbbr (Month self);
int parseMonth(const char *s); int parseMonth (const char *s);
const char* weekdayName(Weekday day); const char* weekdayName (Weekday self);
const char* weekdayAbbr(Weekday day); const char* weekdayAbbr (Weekday self);
int parseWeekday(const char *s); int parseWeekday (const char *s);
int offsetNew(TzOffset *offs, offsetSign sign, uint8_t hours, uint8_t minutes); int offsetNew (TzOffset *self, offsetSign sign,
void printTz(TimeZone *zone); uint8_t hours, uint8_t minutes);
int64_t timezoneAsSeconds(TimeZone *tz); void printTz (TimeZone *self);
int64_t timezoneAsSeconds (TimeZone *self);
int32_t dateTimeGetYear(DateTime *self); int32_t dateTimeGetYear (DateTime *self);
int64_t dateTimeGetTimestampNaive(DateTime *self); int64_t dateTimeGetTimestampNaive (DateTime *self);
int64_t dateTimeGetTimestamp(DateTime *self); int64_t dateTimeGetTimestamp (DateTime *self);
void dateTimeGetTimespec(DateTime *self, struct timespec *ts); void dateTimeGetTimespec (DateTime *self, struct timespec *ts);
Weekday dateTimeGetWeekday(DateTime *self); Weekday dateTimeGetWeekday (DateTime *self);
void dateTimeFromTimestampParts(int64_t seconds, int64_t nanoseconds, DateTime *dt); void dateTimeFromTimestampParts (int64_t seconds, int64_t nanoseconds,
void dateTimeFromTimespec(struct timespec *ts, DateTime *dt); DateTime *dt);
void dateTimeFromTimespec (struct timespec *ts, DateTime *dt);
#endif // !LIBEPOCH_H #endif // !LIBEPOCH_H

28
month.c
View file

@ -36,8 +36,8 @@
#include <strings.h> #include <strings.h>
#include "epoch.h" #include "epoch.h"
uint8_t monthGetDays(Month month, Year *year) { uint8_t monthGetDays(Month self, Year *year) {
switch (month) { switch (self) {
case January: case January:
case March: case March:
case May: case May:
@ -58,23 +58,23 @@ uint8_t monthGetDays(Month month, Year *year) {
} }
} }
uint32_t monthGetSeconds(Month month, Year *year) { uint32_t monthGetSeconds(Month self, Year *year) {
return (int64_t)monthGetDays(month, year) * SECONDS_PER_DAY; return (int64_t)monthGetDays(self, year) * SECONDS_PER_DAY;
} }
int monthIncrement(Month *month) { int monthIncrement(Month *self) {
if (*month == December) if (*self == December)
return 1; return 1;
else else
*month += 1; *self += 1;
return 0; return 0;
} }
int monthDecrement(Month *month) { int monthDecrement(Month *self) {
if (*month == January) if (*self == January)
return 1; return 1;
else else
*month -= 1; *self -= 1;
return 0; return 0;
} }
@ -83,12 +83,12 @@ const char *MonthNames[] = { "January", "February", "March", "April", "May", "Ju
const char *MonthAbbrs[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", const char *MonthAbbrs[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec" }; "Aug", "Sep", "Oct", "Nov", "Dec" };
const char* monthName(Month month) { const char* monthName(Month self) {
return MonthNames[month - 1]; return MonthNames[self - 1];
} }
const char* monthAbbr(Month month) { const char* monthAbbr(Month self) {
return MonthAbbrs[month - 1]; return MonthAbbrs[self - 1];
} }
int parseMonth(const char *s) { int parseMonth(const char *s) {

40
year.c
View file

@ -33,16 +33,16 @@
#include <stdint.h> #include <stdint.h>
#include "epoch.h" #include "epoch.h"
void yearNew(Year *year, int32_t inner) { void yearNew(Year *self, int32_t inner) {
year->year = inner; self->year = inner;
if (inner % 4 == 0 && (inner % 100 != 0 || inner % 400 == 0)) if (inner % 4 == 0 && (inner % 100 != 0 || inner % 400 == 0))
year->tag = leapYear; self->tag = leapYear;
else else
year->tag = normalYear; self->tag = normalYear;
} }
uint16_t yearGetDays(Year *year) { uint16_t yearGetDays(Year *self) {
switch (year->tag) { switch (self->tag) {
case normalYear: case normalYear:
return 365; return 365;
case leapYear: case leapYear:
@ -52,26 +52,26 @@ uint16_t yearGetDays(Year *year) {
} }
} }
int64_t yearGetSeconds(Year *year) { int64_t yearGetSeconds(Year *self) {
return (int64_t)yearGetDays(year) * SECONDS_PER_DAY; return (int64_t)yearGetDays(self) * SECONDS_PER_DAY;
} }
int32_t yearGetInner(Year *year) { int32_t yearGetInner(Year *self) {
return year->year; return self->year;
} }
void yearIncrement(Year *year) { void yearIncrement(Year *self) {
year->year += 1; self->year += 1;
if (year->year % 4 == 0 && (year->year % 100 != 0 || year->year % 400 == 0)) if (self->year % 4 == 0 && (self->year % 100 != 0 || self->year % 400 == 0))
year->tag = leapYear; self->tag = leapYear;
else else
year->tag = normalYear; self->tag = normalYear;
} }
void yearDecrement(Year *year) { void yearDecrement(Year *self) {
year->year -= 1; self->year -= 1;
if (year->year % 4 == 0 && (year->year % 100 != 0 || year->year % 400 == 0)) if (self->year % 4 == 0 && (self->year % 100 != 0 || self->year % 400 == 0))
year->tag = leapYear; self->tag = leapYear;
else else
year->tag = normalYear; self->tag = normalYear;
} }