Sfoglia il codice sorgente

Merge pull request #72 from bmx-ng/task/add-stdc-currentunixtime

Added CurrentUnixTime() function.
Brucey 1 anno fa
parent
commit
4b5cf7a7e8
2 ha cambiato i file con 24 aggiunte e 1 eliminazioni
  1. 7 1
      stdc.mod/stdc.bmx
  2. 17 0
      stdc.mod/stdc.c

+ 7 - 1
stdc.mod/stdc.bmx

@@ -450,7 +450,13 @@ Rem
 bbdoc: Returns the current date and time.
 End Rem
 Function CurrentDateTime(dt:SDateTime Var, utc:Int = True)="bmx_current_datetime"
-	
+
+Rem
+bbdoc: Returns the current Unix time in milliseconds.
+about: The Unix time is a system for describing a point in time, defined as the number of seconds that have
+elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970, minus the number of leap seconds.
+End Rem
+Function CurrentUnixTime:ULong()="bmx_current_unix_time"
 
 End Extern
 

+ 17 - 0
stdc.mod/stdc.c

@@ -1097,6 +1097,17 @@ void bmx_current_datetime(SDateTime * dt, int utc) {
     dt->utc = utc;
     dt->offset = utc ? 0 : bmx_calc_timeoffset_mins(dt);
 }
+
+BBULONG bmx_current_unix_time() {
+	SYSTEMTIME systemTime;
+	GetSystemTime(&systemTime);
+	FILETIME fileTime;
+	SystemTimeToFileTime(&systemTime, &fileTime);
+	ULARGE_INTEGER uli;
+	uli.LowPart = fileTime.dwLowDateTime;
+	uli.HighPart = fileTime.dwHighDateTime;
+	return (uli.QuadPart / 10000) - 11644473600000ULL;
+}
 #else
 int bmx_calc_timeoffset_mins() {
 	time_t rawtime;
@@ -1143,6 +1154,12 @@ void bmx_current_datetime(SDateTime * dt, int utc) {
     dt->utc = utc;
     dt->offset = utc ? 0 : bmx_calc_timeoffset_mins();
 }
+
+BBULONG bmx_current_unix_time() {
+	struct timespec ts;
+	clock_gettime(CLOCK_REALTIME, &ts);
+	return (BBULONG)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
+}
 #endif
 
 int bmx_datetime_from_local_epoch(BBLONG epoch, SDateTime* dt) {