Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2009-04-13 09:47:36 +0000
committerStijn Buys <ingar@osirion.org>2009-04-13 09:47:36 +0000
commitbb2050fa9854064f21e7e01d7da2eb7be9582b52 (patch)
tree4c10f94827b34a6509e490cdfdeb74a03aed4d32 /src/sys
parent3885d7521fdaea218e9e8f98156be472f2e58b5c (diff)
added sys::get_datetime, added win32 time and date functions
Diffstat (limited to 'src/sys')
-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"