Skip to content

Commit

Permalink
Add: Get current time
Browse files Browse the repository at this point in the history
  • Loading branch information
ZFhuang committed May 19, 2024
1 parent d42c6a8 commit 266047f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
65 changes: 62 additions & 3 deletions platform/vita/os_vita.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ void OS_Vita::key(uint32_t p_key, bool p_pressed) {
ev->set_scancode(p_key);
ev->set_unicode(p_key);
input->parse_input_event(ev);
}

bool OS_Vita::has_touchscreen_ui_hint() const {
return true;
};

bool OS_Vita::has_virtual_keyboard() const {
Expand Down Expand Up @@ -603,15 +607,70 @@ bool OS_Vita::set_environment(const String &p_var, const String &p_value) const
}

OS::Date OS_Vita::get_date(bool local) const {
return OS::Date();
SceDateTime sceDateTime;
if (local)
sceRtcGetCurrentClockUtc(&sceDateTime);
else
sceRtcGetCurrentClockLocalTime(&sceDateTime);
// TODO: Daylight calculation.
bool daylight = false;
Date date;
date.day = sceDateTime.day;
date.month = Month(sceDateTime.month);
date.year = sceDateTime.year;
date.weekday = Weekday(sceRtcGetDayOfWeek(sceDateTime.year, sceDateTime.month, sceDateTime.day));
date.dst = daylight;
return date;
}

OS::Time OS_Vita::get_time(bool local) const {
return OS::Time();
SceDateTime sceDateTime;
if (local)
sceRtcGetCurrentClockUtc(&sceDateTime);
else
sceRtcGetCurrentClockLocalTime(&sceDateTime);
Time time;
time.hour = sceDateTime.hour;
time.min = sceDateTime.minute;
time.sec = sceDateTime.second;
return time;
}

OS::TimeZoneInfo OS_Vita::get_time_zone_info() const {
return OS::TimeZoneInfo();
OS::TimeZoneInfo timeZoneInfo;
SceDateTime sceDateTimeUtc;
SceDateTime sceDateTimeLocal;
sceRtcGetCurrentClockUtc(&sceDateTimeUtc);
sceRtcGetCurrentClockLocalTime(&sceDateTimeLocal);
int hourBias = sceDateTimeLocal.hour - sceDateTimeUtc.hour;
if (hourBias < 0) {
hourBias += 24;
}
String sign = (hourBias >= 0) ? "+" : "-";
int local_offset = (hourBias > 0 ? hourBias : -hourBias);
String offset = (local_offset < 10) ? "0" + String::num_int64(local_offset) : String::num_int64(local_offset);
timeZoneInfo.name = "UTC" + sign + offset;
timeZoneInfo.bias = hourBias * 60;
return timeZoneInfo;
}

uint64_t OS_Vita::get_unix_time() const {
uint64_t unixTime;
SceDateTime sceDateTimeUtc;
sceRtcGetCurrentClockUtc(&sceDateTimeUtc);
sceRtcConvertDateTimeToTime64_t(&sceDateTimeUtc, &unixTime);
return unixTime;
}

uint64_t OS_Vita::get_system_time_secs() const {
return get_system_time_msecs() / 1000L;
}

uint64_t OS_Vita::get_system_time_msecs() const {
struct timespec tv_now = { 0, 0 };
clock_gettime(CLOCK_MONOTONIC, &tv_now);
uint64_t longtime = ((uint64_t)tv_now.tv_nsec / 1000000L) + (uint64_t)tv_now.tv_sec * 1000L;
return longtime;
}

void OS_Vita::delay_usec(uint32_t p_usec) const {
Expand Down
4 changes: 4 additions & 0 deletions platform/vita/os_vita.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class OS_Vita : public OS {
virtual bool can_draw() const;

void key(uint32_t p_key, bool p_pressed);
virtual bool has_touchscreen_ui_hint() const;
virtual bool has_virtual_keyboard() const;
virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), bool p_multiline = false, int p_max_input_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
virtual void hide_virtual_keyboard();
Expand Down Expand Up @@ -155,6 +156,9 @@ class OS_Vita : public OS {
virtual Date get_date(bool local = false) const;
virtual Time get_time(bool local = false) const;
virtual TimeZoneInfo get_time_zone_info() const;
virtual uint64_t get_unix_time() const;
virtual uint64_t get_system_time_secs() const;
virtual uint64_t get_system_time_msecs() const;
virtual void delay_usec(uint32_t p_usec) const;
virtual uint64_t get_ticks_usec() const;
virtual String get_stdin_string();
Expand Down

0 comments on commit 266047f

Please sign in to comment.