mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:47:35 +00:00
Add a simple clock window to guitest2.
This is driven by mousedown events right now, since there are no timers.
This commit is contained in:
parent
2dc9c86bad
commit
e04ba0a83c
7 changed files with 113 additions and 10 deletions
|
@ -27,9 +27,46 @@ char* ctime(const time_t*)
|
|||
return const_cast<char*>("ctime() not implemented");
|
||||
}
|
||||
|
||||
struct tm* localtime(const time_t*)
|
||||
inline bool is_leap_year(unsigned year)
|
||||
{
|
||||
assert(false);
|
||||
return ((year % 4 == 0) && ((year % 100 != 0) || (year % 400) == 0));
|
||||
}
|
||||
|
||||
static void time_to_tm(struct tm* tm, time_t t)
|
||||
{
|
||||
static const unsigned seconds_per_day = 60 * 60 * 24;
|
||||
static const unsigned days_per_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
unsigned days = t / seconds_per_day;
|
||||
unsigned rem = t % seconds_per_day;
|
||||
tm->tm_sec = rem % 60;
|
||||
rem /= 60;
|
||||
tm->tm_min = rem % 60;
|
||||
tm->tm_hour = rem / 60;
|
||||
tm->tm_wday = (4 + days) % 7;
|
||||
unsigned year;
|
||||
for (year = 1970; days >= 365 + is_leap_year(year); ++year)
|
||||
days -= 365 + is_leap_year(year);
|
||||
tm->tm_year = year - 1900;
|
||||
tm->tm_yday = days;
|
||||
tm->tm_mday = 1;
|
||||
if (is_leap_year(year) && days == 59)
|
||||
++tm->tm_mday;
|
||||
if (is_leap_year(year) && days >= 59)
|
||||
--days;
|
||||
unsigned month;
|
||||
for (month = 0; month < 11 && days >= days_per_month[month]; ++month)
|
||||
days -= days_per_month[month];
|
||||
tm->tm_mon = month;
|
||||
tm->tm_mday += days;
|
||||
}
|
||||
|
||||
struct tm* localtime(const time_t* t)
|
||||
{
|
||||
if (!t)
|
||||
return nullptr;
|
||||
static struct tm tm_buf;
|
||||
time_to_tm(&tm_buf, *t);
|
||||
return &tm_buf;
|
||||
}
|
||||
|
||||
long timezone = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue