Add epoch
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
timelinux.c
|
||||
)
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "time/timelinux.h"
|
||||
#include <time.h>
|
||||
|
||||
double_t timeGetRealLinux(void) {
|
||||
struct timespec ts;
|
||||
|
||||
if(clock_gettime(CLOCK_REALTIME, &ts) != 0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return (
|
||||
((double)ts.tv_sec) +
|
||||
((double)ts.tv_nsec / 1000000000.0)
|
||||
);
|
||||
}
|
||||
|
||||
double_t timeGetRealTimeZoneLinux(void) {
|
||||
time_t now = time(NULL);
|
||||
struct tm local_tm;
|
||||
localtime_r(&now, &local_tm);
|
||||
return (double_t)(local_tm.tm_gmtoff);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
/**
|
||||
* Returns the real current time, in seconds since January 1, 1970.
|
||||
*
|
||||
* @return The real current time, in seconds since January 1, 1970.
|
||||
*/
|
||||
double_t timeGetRealLinux(void);
|
||||
|
||||
/**
|
||||
* Returns the real time zone offset in seconds from UTC.
|
||||
*
|
||||
* @return The real time zone offset in seconds from UTC.
|
||||
*/
|
||||
double_t timeGetRealTimeZoneLinux(void);
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "time/timesdl2.h"
|
||||
#include "time/timelinux.h"
|
||||
|
||||
#define timeTickPlatform timeTickSDL2
|
||||
#define timeGetDeltaPlatform timeGetDeltaSDL2
|
||||
#define timeGetRealPlatform timeGetRealLinux
|
||||
#define timeGetRealTimeZonePlatform timeGetRealTimeZoneLinux
|
||||
Reference in New Issue
Block a user