1 module libxlsxd.datetime;
2 
3 import std.datetime.date : DateTime, Date, TimeOfDay;
4 
5 import libxlsxd.xlsxwrap;
6 
7 @safe:
8 
9 struct Datetime {
10 	import std.conv : to;
11 
12 	lxw_datetime handle;
13 
14 	version(No_Overloads_Or_Templates) {
15 		static Datetime fromDateTime(DateTime ddt) @safe {
16 			Datetime ret;
17 			ret.handle.year = ddt.year;
18 			ret.handle.month = ddt.month;
19 			ret.handle.day = ddt.day;
20 			ret.handle.hour = ddt.hour;
21 			ret.handle.min = ddt.minute;
22 			ret.handle.sec = to!double(ddt.second);
23 			return ret;
24 		}
25 
26 		static Datetime fromDate(Date d) @safe {
27 			Datetime ret;
28 			ret.handle.year = d.year;
29 			ret.handle.month = d.month;
30 			ret.handle.day = d.day;
31 			ret.handle.hour = 0;
32 			ret.handle.min = 0;
33 			ret.handle.sec = 0;
34 			return ret;
35 		}
36 
37 		static Datetime fromTimeOfDay(TimeOfDay tod) @safe {
38 			Datetime ret;
39 			ret.handle.year = 0;
40 			ret.handle.month = 0;
41 			ret.handle.day = 0;
42 			ret.handle.hour = tod.hour;
43 			ret.handle.min = tod.minute;
44 			ret.handle.sec = to!double(tod.second);
45 			return ret;
46 		}
47 
48 		static Datetime fromLXW_Datetime(lxw_datetime lxw) @safe {
49 			Datetime ret;
50 			ret.handle = lxw;
51 			return ret;
52 		}
53 	} else {
54 		this(lxw_datetime dt) @nogc nothrow pure @safe {
55 			this.handle = handle;
56 		}
57 
58 		this(DateTime ddt) @safe {
59 			this.handle.year = ddt.year;
60 			this.handle.month = ddt.month;
61 			this.handle.day = ddt.day;
62 			this.handle.hour = ddt.hour;
63 			this.handle.min = ddt.minute;
64 			this.handle.sec = to!double(ddt.second);
65 		}
66 
67 		this(Date d) @safe {
68 			this.handle.year = d.year;
69 			this.handle.month = d.month;
70 			this.handle.day = d.day;
71 			this.handle.hour = 0;
72 			this.handle.min = 0;
73 			this.handle.sec = 0;
74 		}
75 
76 		this(TimeOfDay tod) @safe {
77 			this.handle.year = 0;
78 			this.handle.month = 0;
79 			this.handle.day = 0;
80 			this.handle.hour = tod.hour;
81 			this.handle.min = tod.minute;
82 			this.handle.sec = to!double(tod.second);
83 		}
84 	}
85 }