luxos/SysCore/lib/time.c

81 lines
2.6 KiB
C
Raw Normal View History

2021-09-14 15:34:14 +00:00
#include <system.h>
#include <time.h>
const char* clock_months[] = {0,
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
const char* clock_weekdays[] = {0,
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
byte clock_months_len[] = {
0,
31, // January
28, // February
31, // March
30, // April
31, // May
30, // June
31, // July
31, // August
30, // September
31, // October
30, // November
31 // December
};
void _CLOCK_INC(TIME *tim)
{
// New minute
if (++tim->seconds > 59) {
tim->seconds = 0;
// New hour
if (++tim->minutes > 59) {
tim->minutes = 0;
tim->hours++;
if (tim->hours == 12 && tim->am_pm == 1) { // 11:59pm -> 0:00am
tim->hours = 0; tim->am_pm = 0;
// New day
tim->weekday = 1+(tim->weekday%7);
// Leap years
if ((tim->day==28) && (tim->month==2)) { tim->day++; return; }
// New month
if (++tim->day > clock_months_len[tim->month]) {
tim->day = 1;
// New year
if (++tim->month>12) {
tim->month = 1;
// New century
if (++tim->year > 99) { tim->year = 0; tim->century++;}
}
}
}
else if (tim->hours == 12 && tim->am_pm == 0) tim->am_pm = 1; // 11:59am -> 12:00pm
else if (tim->hours == 13 && tim->am_pm == 1) tim->hours = 1; // 12:59pm -> 1:59pm
}
}
}
/* ASCTIME Formats: ****************************************************************
* 1 W = weekday, M = month, D = day, H = Hour, M = Minute, S = Second, Y = year) *
* A = AM/PM *
* 2 Use capital letter for one letter/digit; else, use lower *
* *
* Example: asctime (time, "Today is: %W3 %D2 %m") *
* Result: Today is: Mon 22 June *
************************************************************************************/
/*char* asctime (TIME time, char* format)
{
char str[100];
int l = strlen(format), i;
byte special = 0;
for (i=0; i<l-1 && i<100; i++) {
if (format[i] == '%') switch (format[i+1]) {
case 'W':
}*/