Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sys/sys.cc63
-rw-r--r--src/sys/sys.h2
2 files changed, 63 insertions, 2 deletions
diff --git a/src/sys/sys.cc b/src/sys/sys.cc
index 01c9e3b..f99d533 100644
--- a/src/sys/sys.cc
+++ b/src/sys/sys.cc
@@ -125,6 +125,37 @@ void signal(int signum, signalfunc handler)
#endif
}
+/*
+
+POSIX:
+
+ struct tm {
+ int tm_sec; // seconds
+ int tm_min; // minutes
+ int tm_hour; // hours
+ int tm_mday; // day of the month
+ int tm_mon; // month
+ int tm_year; // year
+ int tm_wday; // day of the week
+ int tm_yday; // day in the year
+ int tm_isdst; // daylight saving time
+ };
+
+WIN32:
+
+ typedef struct _SYSTEMTIME {
+ WORD wYear;
+ WORD wMonth;
+ WORD wDayOfWeek;
+ WORD wDay;
+ WORD wHour;
+ WORD wMinute;
+ WORD wSecond;
+ WORD wMilliseconds;
+ } SYSTEMTIME, *PSYSTEMTIME;
+
+*/
+
unsigned long time()
{
#ifndef _WIN32
@@ -133,7 +164,10 @@ unsigned long time()
::localtime_r(&epochtime, &localtime);
return ((unsigned long)(localtime.tm_sec + localtime.tm_min*60 + localtime.tm_hour*3600));
#else
- return 0;
+ SYSTEMTIME localtime;
+ ::GetLocalTime(&localtime);
+
+ return ((unsigned long)(localtime.wSecond + localtime.wMinute*60 + localtime.wHour*3600));
#endif
}
@@ -146,10 +180,35 @@ void sleep(float seconds)
#endif
}
+void get_datetime(int &year, int & month, int & day, int & hours, int & minutes)
+{
+#ifndef _WIN32
+ struct ::tm localtime;
+ time_t epochtime = ::time(0);
+ ::localtime_r(&epochtime, &localtime);
+
+ year = localtime.tm_year + 1900;
+ month = localtime.tm_mon +1;
+ day = localtime.tm_mday;
+
+ hours = localtime.tm_hour;
+ minutes = localtime.tm_min;
+#else
+ SYSTEMTIME localtime;
+ ::GetLocalTime(&localtime);
+
+ year = localtime.wYear;
+ month = localtime.wMonth;
+ day = localtime.wDay;
+
+ hours = localtime.wHour;
+ minutes = localtime.wMinute;
+#endif
+}
+
void quit(int status)
{
::exit(status);
}
}
-
diff --git a/src/sys/sys.h b/src/sys/sys.h
index 5e41daa..3d94bcb 100644
--- a/src/sys/sys.h
+++ b/src/sys/sys.h
@@ -45,6 +45,8 @@ void sleep(float seconds);
/// return the current system time of day, in seconds after midnight
unsigned long time();
+/// get the current system date and time
+void get_datetime(int &year, int & month, int & day, int & hours, int & minutes);
}
#include "sys/consoleinterface.h"