1 /// Author: Aziz Köksal
2 /// License: GPL3
3 /// $(Maturity high)
4 module dil.Time;
5 
6 import dil.String;
7 import common;
8 
9 import core.stdc.time : time_t, time, ctime;
10 
11 /// Some convenience functions for dealing with C's time functions.
12 struct Time
13 {
14 static:
15   /// Returns the current date as a string.
16   char[] now()
17   {
18     time_t time_val;
19     core.stdc.time.time(&time_val);
20     // ctime returns a pointer to a static array.
21     char* timeStr = ctime(&time_val);
22     return MString(timeStr, '\n')[];
23   }
24 
25   /// Returns the time of timeStr: hh:mm:ss
26   cstring time(cstring timeStr)
27   {
28     return timeStr[11..19];
29   }
30 
31   /// Returns the month and day of timeStr: Mmm dd
32   cstring month_day(cstring timeStr)
33   {
34     return timeStr[4..10];
35   }
36 
37   /// Returns the year of timeStr: yyyy
38   cstring year(cstring timeStr)
39   {
40     return timeStr[20..24];
41   }
42 }