PageRenderTime 29ms CodeModel.GetById 22ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/platform/win/scaffold/time.d

http://github.com/wilkie/djehuty
D | 101 lines | 62 code | 24 blank | 15 comment | 8 complexity | 2b586315778df21d4f2c89539b2a687e MD5 | raw file
  1/*
  2 * time.d
  3 *
  4 * This file implements the Scaffold for platform specific Time
  5 * operations in Windows.
  6 *
  7 * Author: Dave Wilkinson
  8 *
  9 */
 10
 11module scaffold.time;
 12
 13pragma(lib, "winmm.lib");
 14
 15import platform.win.common;
 16
 17import core.date;
 18import core.definitions;
 19import core.string;
 20
 21// Timing
 22
 23import io.console;
 24
 25string TimeZoneGet() {
 26	TIME_ZONE_INFORMATION tzi;
 27	GetTimeZoneInformation(&tzi);
 28
 29	// Use Bias information.
 30
 31	// The Bias entry is calculated as the difference from UTC such that:
 32	// UTC = lcoal time + bias.
 33
 34	// Therefore, we need to use the negative of the Bias.
 35
 36	int diff_hr, diff_min;
 37
 38	diff_hr = -tzi.Bias / 60;
 39	diff_min = -tzi.Bias % 60;
 40
 41	string ret = "UTC" ~ toStr(diff_hr) ~ ":";
 42	if (diff_min < 10) {
 43		ret ~= "0";
 44	}
 45	ret ~= toStr(diff_min);
 46
 47	// Use other information
 48
 49	wchar[] tzname = "";
 50	size_t len = strlen(tzi.StandardName.ptr);
 51	if (len != 0) {
 52		tzname = new wchar[len];
 53		tzname[0..len] = (tzi.StandardName.ptr)[0..len];
 54		switch (tzname) {
 55			case "EST":
 56				if (diff_hr != -5) { break; }
 57			case "Eastern Standard Time":
 58				return "Eastern Standard Time";
 59
 60			case "PST":
 61				if (diff_hr != -8) { break; }
 62			case "Pacific Standard Time":
 63				return "Pacific Standard Time";
 64
 65			default:
 66				break;
 67		}
 68	}
 69
 70	return ret;
 71}
 72
 73long TimeGet() {
 74	SYSTEMTIME sysTime;
 75	GetSystemTime(&sysTime);
 76	long micros;
 77
 78	micros = cast(long)sysTime.wHour;
 79	micros *= 60L;
 80	micros += cast(long)sysTime.wMinute;
 81	micros *= 60L;
 82	micros += cast(long)sysTime.wSecond;
 83	micros *= 1000;
 84	micros += cast(long)sysTime.wMilliseconds;
 85	micros *= 1000L;
 86
 87	return micros;
 88}
 89
 90long SystemTimeGet() {
 91	return timeGetTime();
 92}
 93
 94void DateGet(out Month month, out uint day, out uint year) {
 95	SYSTEMTIME sysTime;
 96	GetSystemTime(&sysTime);
 97	
 98	month = cast(Month)(sysTime.wMonth - 1);
 99	day = sysTime.wDay;
100	year = sysTime.wYear;
101}