diff --git a/include/epoch.h b/include/epoch.h index f73d61d..1cd3b1c 100644 --- a/include/epoch.h +++ b/include/epoch.h @@ -46,7 +46,7 @@ typedef enum { } yearTag; typedef struct { - yearTag tag; + yearTag tag; uint32_t year; } Year; @@ -117,35 +117,37 @@ typedef enum { NanoSecondPrecision, } datetimePrecision; -void yearNew(Year *year, int32_t inner); -uint16_t yearGetDays(Year *year); -int64_t yearGetSeconds(Year *year); -int32_t yearGetInner(Year *year); -void yearIncrement(Year *year); -void yearDecrement(Year *year); +void yearNew (Year *self, int32_t inner); +uint16_t yearGetDays (Year *self); +int64_t yearGetSeconds (Year *self); +int32_t yearGetInner (Year *self); +void yearIncrement (Year *self); +void yearDecrement (Year *self); -uint8_t monthGetDays(Month month, Year *year); -uint32_t monthGetSeconds(Month month, Year *year); -int monthIncrement(Month *month); -int monthDecrement(Month *month); -const char* monthName(Month month); -const char* monthAbbr(Month month); -int parseMonth(const char *s); +uint8_t monthGetDays (Month self, Year *year); +uint32_t monthGetSeconds (Month self, Year *year); +int monthIncrement (Month *self); +int monthDecrement (Month *self); +const char* monthName (Month self); +const char* monthAbbr (Month self); +int parseMonth (const char *s); -const char* weekdayName(Weekday day); -const char* weekdayAbbr(Weekday day); -int parseWeekday(const char *s); +const char* weekdayName (Weekday self); +const char* weekdayAbbr (Weekday self); +int parseWeekday (const char *s); -int offsetNew(TzOffset *offs, offsetSign sign, uint8_t hours, uint8_t minutes); -void printTz(TimeZone *zone); -int64_t timezoneAsSeconds(TimeZone *tz); +int offsetNew (TzOffset *self, offsetSign sign, + uint8_t hours, uint8_t minutes); +void printTz (TimeZone *self); +int64_t timezoneAsSeconds (TimeZone *self); -int32_t dateTimeGetYear(DateTime *self); -int64_t dateTimeGetTimestampNaive(DateTime *self); -int64_t dateTimeGetTimestamp(DateTime *self); -void dateTimeGetTimespec(DateTime *self, struct timespec *ts); -Weekday dateTimeGetWeekday(DateTime *self); -void dateTimeFromTimestampParts(int64_t seconds, int64_t nanoseconds, DateTime *dt); -void dateTimeFromTimespec(struct timespec *ts, DateTime *dt); +int32_t dateTimeGetYear (DateTime *self); +int64_t dateTimeGetTimestampNaive (DateTime *self); +int64_t dateTimeGetTimestamp (DateTime *self); +void dateTimeGetTimespec (DateTime *self, struct timespec *ts); +Weekday dateTimeGetWeekday (DateTime *self); +void dateTimeFromTimestampParts (int64_t seconds, int64_t nanoseconds, + DateTime *dt); +void dateTimeFromTimespec (struct timespec *ts, DateTime *dt); #endif // !LIBEPOCH_H diff --git a/month.c b/month.c index 67c5a56..d9966fa 100644 --- a/month.c +++ b/month.c @@ -36,8 +36,8 @@ #include #include "epoch.h" -uint8_t monthGetDays(Month month, Year *year) { - switch (month) { +uint8_t monthGetDays(Month self, Year *year) { + switch (self) { case January: case March: case May: @@ -58,23 +58,23 @@ uint8_t monthGetDays(Month month, Year *year) { } } -uint32_t monthGetSeconds(Month month, Year *year) { - return (int64_t)monthGetDays(month, year) * SECONDS_PER_DAY; +uint32_t monthGetSeconds(Month self, Year *year) { + return (int64_t)monthGetDays(self, year) * SECONDS_PER_DAY; } -int monthIncrement(Month *month) { - if (*month == December) +int monthIncrement(Month *self) { + if (*self == December) return 1; else - *month += 1; + *self += 1; return 0; } -int monthDecrement(Month *month) { - if (*month == January) +int monthDecrement(Month *self) { + if (*self == January) return 1; else - *month -= 1; + *self -= 1; 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", "Aug", "Sep", "Oct", "Nov", "Dec" }; -const char* monthName(Month month) { - return MonthNames[month - 1]; +const char* monthName(Month self) { + return MonthNames[self - 1]; } -const char* monthAbbr(Month month) { - return MonthAbbrs[month - 1]; +const char* monthAbbr(Month self) { + return MonthAbbrs[self - 1]; } int parseMonth(const char *s) { diff --git a/year.c b/year.c index af864c9..66d2940 100644 --- a/year.c +++ b/year.c @@ -33,16 +33,16 @@ #include #include "epoch.h" -void yearNew(Year *year, int32_t inner) { - year->year = inner; +void yearNew(Year *self, int32_t inner) { + self->year = inner; if (inner % 4 == 0 && (inner % 100 != 0 || inner % 400 == 0)) - year->tag = leapYear; + self->tag = leapYear; else - year->tag = normalYear; + self->tag = normalYear; } -uint16_t yearGetDays(Year *year) { - switch (year->tag) { +uint16_t yearGetDays(Year *self) { + switch (self->tag) { case normalYear: return 365; case leapYear: @@ -52,26 +52,26 @@ uint16_t yearGetDays(Year *year) { } } -int64_t yearGetSeconds(Year *year) { - return (int64_t)yearGetDays(year) * SECONDS_PER_DAY; +int64_t yearGetSeconds(Year *self) { + return (int64_t)yearGetDays(self) * SECONDS_PER_DAY; } -int32_t yearGetInner(Year *year) { - return year->year; +int32_t yearGetInner(Year *self) { + return self->year; } -void yearIncrement(Year *year) { - year->year += 1; - if (year->year % 4 == 0 && (year->year % 100 != 0 || year->year % 400 == 0)) - year->tag = leapYear; +void yearIncrement(Year *self) { + self->year += 1; + if (self->year % 4 == 0 && (self->year % 100 != 0 || self->year % 400 == 0)) + self->tag = leapYear; else - year->tag = normalYear; + self->tag = normalYear; } -void yearDecrement(Year *year) { - year->year -= 1; - if (year->year % 4 == 0 && (year->year % 100 != 0 || year->year % 400 == 0)) - year->tag = leapYear; +void yearDecrement(Year *self) { + self->year -= 1; + if (self->year % 4 == 0 && (self->year % 100 != 0 || self->year % 400 == 0)) + self->tag = leapYear; else - year->tag = normalYear; + self->tag = normalYear; }