From 04ae97a6ec51315ebc8567fa784b73f06b023d82 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 6 Nov 2022 15:09:38 +0100 Subject: [PATCH] libc: Add difftime() --- libs/libc/include/time.h | 3 +++ libs/libc/src/time.cpp | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/libs/libc/include/time.h b/libs/libc/include/time.h index 3921b6ff..1e66f35a 100644 --- a/libs/libc/include/time.h +++ b/libs/libc/include/time.h @@ -77,6 +77,9 @@ extern "C" /* Fills str with a formatted string representation of time according to the format string. */ size_t strftime(char* str, size_t max, const char* format, const struct tm* time); + /* Returns the difference between two times. */ + double difftime(time_t time2, time_t time1); + #ifdef __cplusplus } #endif diff --git a/libs/libc/src/time.cpp b/libs/libc/src/time.cpp index 4643eec5..f6516871 100644 --- a/libs/libc/src/time.cpp +++ b/libs/libc/src/time.cpp @@ -175,4 +175,9 @@ extern "C" { return broken_down_to_unix(time->tm_year, time->tm_yday, time->tm_hour, time->tm_min, time->tm_sec); } + + double difftime(time_t time2, time_t time1) + { + return (double)(time2 - time1); + } } \ No newline at end of file