Style fixes
This commit is contained in:
parent
f86e4ad966
commit
dfff32378c
@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2022 Ali Mashtizadeh
|
||||||
|
* All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -28,7 +32,7 @@ KTime_Init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
KTime_IsLeapYear(uint64_t year)
|
KTimeIsLeapYear(uint64_t year)
|
||||||
{
|
{
|
||||||
if ((year % 4) != 0)
|
if ((year % 4) != 0)
|
||||||
return false;
|
return false;
|
||||||
@ -40,11 +44,11 @@ KTime_IsLeapYear(uint64_t year)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
KTime_DaysInMonth(uint64_t year, uint64_t month)
|
KTimeDaysInMonth(uint64_t year, uint64_t month)
|
||||||
{
|
{
|
||||||
static const uint64_t days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
static const uint64_t days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||||
|
|
||||||
if ((month == 2) && KTime_IsLeapYear(year))
|
if ((month == 2) && KTimeIsLeapYear(year))
|
||||||
return 29;
|
return 29;
|
||||||
else
|
else
|
||||||
return days[month];
|
return days[month];
|
||||||
@ -61,7 +65,7 @@ KTime_Fixup(KTime *tm)
|
|||||||
if (tm->yday == -1) {
|
if (tm->yday == -1) {
|
||||||
uint64_t yday = 0;
|
uint64_t yday = 0;
|
||||||
for (m = 0; m < tm->month; m++) {
|
for (m = 0; m < tm->month; m++) {
|
||||||
yday += KTime_DaysInMonth(tm->year, m);
|
yday += KTimeDaysInMonth(tm->year, m);
|
||||||
}
|
}
|
||||||
yday += tm->mday;
|
yday += tm->mday;
|
||||||
tm->yday = yday;
|
tm->yday = yday;
|
||||||
@ -77,7 +81,7 @@ KTime_ToEpoch(const KTime *tm)
|
|||||||
|
|
||||||
// Convert to UNIX epoch
|
// Convert to UNIX epoch
|
||||||
for (y = 1970; y < tm->year; y++) {
|
for (y = 1970; y < tm->year; y++) {
|
||||||
if (KTime_IsLeapYear(y))
|
if (KTimeIsLeapYear(y))
|
||||||
days += 366;
|
days += 366;
|
||||||
else
|
else
|
||||||
days += 365;
|
days += 365;
|
||||||
@ -86,7 +90,7 @@ KTime_ToEpoch(const KTime *tm)
|
|||||||
if (tm->yday == -1) {
|
if (tm->yday == -1) {
|
||||||
uint64_t yday = 0;
|
uint64_t yday = 0;
|
||||||
for (m = 0; m < tm->month; m++) {
|
for (m = 0; m < tm->month; m++) {
|
||||||
yday += KTime_DaysInMonth(tm->year, m);
|
yday += KTimeDaysInMonth(tm->year, m);
|
||||||
}
|
}
|
||||||
yday += tm->mday;
|
yday += tm->mday;
|
||||||
days += yday;
|
days += yday;
|
||||||
@ -129,7 +133,7 @@ KTime_FromEpoch(UnixEpoch epoch, KTime *tm)
|
|||||||
|
|
||||||
for (y = 1970; ; y++) {
|
for (y = 1970; ; y++) {
|
||||||
uint64_t daysOfYear;
|
uint64_t daysOfYear;
|
||||||
if (KTime_IsLeapYear(y)) {
|
if (KTimeIsLeapYear(y)) {
|
||||||
daysOfYear = 366;
|
daysOfYear = 366;
|
||||||
} else {
|
} else {
|
||||||
daysOfYear = 365;
|
daysOfYear = 365;
|
||||||
@ -144,7 +148,7 @@ KTime_FromEpoch(UnixEpoch epoch, KTime *tm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (m = 0; ; m++) {
|
for (m = 0; ; m++) {
|
||||||
uint64_t daysOfMonth = KTime_DaysInMonth(tm->year, m);
|
uint64_t daysOfMonth = KTimeDaysInMonth(tm->year, m);
|
||||||
|
|
||||||
if (days < daysOfMonth) {
|
if (days < daysOfMonth) {
|
||||||
tm->mday = days;
|
tm->mday = days;
|
||||||
|
Loading…
Reference in New Issue
Block a user