-
-
Notifications
You must be signed in to change notification settings - Fork 700
/
package.d
165 lines (145 loc) · 5.48 KB
/
package.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Written in the D programming language
/++
$(SCRIPT inhibitQuickIndex = 1;)
Phobos provides the following functionality for time:
$(DIVC quickindex,
$(BOOKTABLE ,
$(TR $(TH Functionality) $(TH Symbols)
)
$(TR
$(TD Points in Time)
$(TD
$(REF_ALTTEXT Date, Date, std, datetime, date)$(NBSP)
$(REF_ALTTEXT TimeOfDay, TimeOfDay, std, datetime, date)$(NBSP)
$(REF_ALTTEXT DateTime, DateTime, std, datetime, date)$(NBSP)
$(REF_ALTTEXT SysTime, SysTime, std, datetime, systime)$(NBSP)
)
)
$(TR
$(TD Timezones)
$(TD
$(REF_ALTTEXT TimeZone, TimeZone, std, datetime, timezone)$(NBSP)
$(REF_ALTTEXT UTC, UTC, std, datetime, timezone)$(NBSP)
$(REF_ALTTEXT LocalTime, LocalTime, std, datetime, timezone)$(NBSP)
$(REF_ALTTEXT PosixTimeZone, PosixTimeZone, std, datetime, timezone)$(NBSP)
$(REF_ALTTEXT WindowsTimeZone, WindowsTimeZone, std, datetime, timezone)$(NBSP)
$(REF_ALTTEXT SimpleTimeZone, SimpleTimeZone, std, datetime, timezone)$(NBSP)
)
)
$(TR
$(TD Intervals and Ranges of Time)
$(TD
$(REF_ALTTEXT Interval, Interval, std, datetime, interval)$(NBSP)
$(REF_ALTTEXT PosInfInterval, PosInfInterval, std, datetime, interval)$(NBSP)
$(REF_ALTTEXT NegInfInterval, NegInfInterval, std, datetime, interval)$(NBSP)
)
)
$(TR
$(TD Durations of Time)
$(TD
$(REF_ALTTEXT Duration, Duration, core, time)$(NBSP)
$(REF_ALTTEXT weeks, weeks, core, time)$(NBSP)
$(REF_ALTTEXT days, days, core, time)$(NBSP)
$(REF_ALTTEXT hours, hours, core, time)$(NBSP)
$(REF_ALTTEXT minutes, minutes, core, time)$(NBSP)
$(REF_ALTTEXT seconds, seconds, core, time)$(NBSP)
$(REF_ALTTEXT msecs, msecs, core, time)$(NBSP)
$(REF_ALTTEXT usecs, usecs, core, time)$(NBSP)
$(REF_ALTTEXT hnsecs, hnsecs, core, time)$(NBSP)
$(REF_ALTTEXT nsecs, nsecs, core, time)$(NBSP)
)
)
$(TR
$(TD Time Measurement and Benchmarking)
$(TD
$(REF_ALTTEXT MonoTime, MonoTime, core, time)$(NBSP)
$(REF_ALTTEXT StopWatch, StopWatch, std, datetime, stopwatch)$(NBSP)
$(REF_ALTTEXT benchmark, benchmark, std, datetime, stopwatch)$(NBSP)
)
)
))
This functionality is separated into the following modules
$(UL
$(LI $(MREF std, datetime, date) for points in time without timezones.)
$(LI $(MREF std, datetime, timezone) for classes which represent timezones.)
$(LI $(MREF std, datetime, systime) for a point in time with a timezone.)
$(LI $(MREF std, datetime, interval) for types which represent series of points in time.)
$(LI $(MREF std, datetime, stopwatch) for measuring time.)
)
See_Also:
$(DDLINK intro-to-datetime, Introduction to std.datetime,
Introduction to std.datetime)<br>
$(HTTP en.wikipedia.org/wiki/ISO_8601, ISO 8601)<br>
$(HTTP en.wikipedia.org/wiki/Tz_database,
Wikipedia entry on TZ Database)<br>
$(HTTP en.wikipedia.org/wiki/List_of_tz_database_time_zones,
List of Time Zones)<br>
License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
Authors: $(HTTP jmdavisprog.com, Jonathan M Davis) and Kato Shoichi
Source: $(PHOBOSSRC std/datetime/package.d)
+/
module std.datetime;
/// Get the current time from the system clock
@safe unittest
{
import std.datetime.systime : SysTime, Clock;
SysTime currentTime = Clock.currTime();
}
/**
Construct a specific point in time without timezone information
and get its ISO string.
*/
@safe unittest
{
import std.datetime.date : DateTime;
auto dt = DateTime(2018, 1, 1, 12, 30, 10);
assert(dt.toISOString() == "20180101T123010");
assert(dt.toISOExtString() == "2018-01-01T12:30:10");
}
/**
Construct a specific point in time in the UTC timezone and
add two days.
*/
@safe unittest
{
import std.datetime.systime : SysTime;
import std.datetime.timezone : UTC;
import core.time : days;
auto st = SysTime(DateTime(2018, 1, 1, 12, 30, 10), UTC());
assert(st.toISOExtString() == "2018-01-01T12:30:10Z");
st += 2.days;
assert(st.toISOExtString() == "2018-01-03T12:30:10Z");
}
public import core.time;
public import std.datetime.date;
public import std.datetime.interval;
public import std.datetime.systime;
public import std.datetime.timezone;
import core.exception : AssertError;
import std.functional : unaryFun;
import std.traits;
import std.typecons : Flag, Yes, No;
// Verify module example.
@safe unittest
{
auto currentTime = Clock.currTime();
auto timeString = currentTime.toISOExtString();
auto restoredTime = SysTime.fromISOExtString(timeString);
}
// Verify Examples for core.time.Duration which couldn't be in core.time.
@safe unittest
{
assert(std.datetime.Date(2010, 9, 7) + dur!"days"(5) ==
std.datetime.Date(2010, 9, 12));
assert(std.datetime.Date(2010, 9, 7) - std.datetime.Date(2010, 10, 3) ==
dur!"days"(-26));
}
@safe unittest
{
import std.traits : hasUnsharedAliasing;
/* https://issues.dlang.org/show_bug.cgi?id=6642 */
static assert(!hasUnsharedAliasing!Date);
static assert(!hasUnsharedAliasing!TimeOfDay);
static assert(!hasUnsharedAliasing!DateTime);
static assert(!hasUnsharedAliasing!SysTime);
}