comparison src/dil/Time.d @ 806:bcb74c9b895c

Moved out files in the trunk folder to the root.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sun, 09 Mar 2008 00:12:19 +0100
parents trunk/src/dil/Time.d@c24be8d4f6ab
children
comparison
equal deleted inserted replaced
805:a3fab8b74a7d 806:bcb74c9b895c
1 /++
2 Author: Aziz Köksal
3 License: GPL3
4 +/
5 module dil.Time;
6
7 import tango.stdc.time : time_t, time, ctime;
8 import tango.stdc.string : strlen;
9
10 /// Some convenience functions for dealing with C's time functions.
11 struct Time
12 {
13 static:
14 /// Returns the current date as a string.
15 char[] toString()
16 {
17 time_t time_val;
18 .time(&time_val);
19 char* str = ctime(&time_val); // ctime returns a pointer to a static array.
20 char[] timeStr = str[0 .. strlen(str)-1]; // -1 removes trailing '\n'.
21 return timeStr.dup;
22 }
23
24 /// Returns the time of timeStr: hh:mm:ss
25 char[] time(char[] timeStr)
26 {
27 return timeStr[11..19];
28 }
29
30 /// Returns the month and day of timeStr: Mmm dd
31 char[] month_day(char[] timeStr)
32 {
33 return timeStr[4..10];
34 }
35
36 /// Returns the year of timeStr: yyyy
37 char[] year(char[] timeStr)
38 {
39 return timeStr[20..24];
40 }
41 }