source: Include/Classes/System/TimeSpan.ab@ 164

Last change on this file since 164 was 106, checked in by OverTaker, 18 years ago

TimeSpan.ab実装。

File size: 4.7 KB
RevLine 
[106]1Class TimeSpan
2 m_Time As Int64
3Public
4 Static MaxValue = 3162240000000000000 As Int64
5 Static MinValue = -3162240000000000000 As Int64
6 Static TicksPerDay = 864000000000 As Int64
7 Static TicksPerHour = 36000000000 As Int64
8 Static TicksPerMinute = 600000000 As Int64
9 Static TicksPerSecond = 10000000 As Int64
10 Static TicksPerMillisecond = 10000 As Int64
11 Static Zero = 0 As Int64
12
13 Sub TimeSpan(ticks As Int64)
14 If (ticks > MaxValue) Or (ticks < MinValue) Then
15 'ArgumentOutOfRangeException
16 debug
17 Exit Sub
18 End If
19 m_Time = ticks
20 End Sub
21
22 Sub TimeSpan(ByRef ts As TimeSpan)
23 m_Time = ts.m_Time
24 End Sub
25
26 Sub ~TimeSpan()
27 End Sub
28
29 Function Operator+ (ByRef ts As TimeSpan) As TimeSpan
30 Return FromTicks(m_Time + ts.m_Time)
31 End Function
32
33 Function Operator- (ByRef ts As TimeSpan) As TimeSpan
34 Return FromTicks(m_Time - ts.m_Time)
35 End Function
36
37 Function Operator* (value As Long) As TimeSpan
38 Return FromTicks(m_Time * value)
39 End Function
40
41 Function Operator/ (value As Long) As TimeSpan
42 Return FromTicks(m_Value \ value)
43 End Function
44
45 Function Operator== (ByRef ts As TimeSpan) As Boolean
46 Return Equals(ts)
47 End Function
48
49 Function Operator<> (ByRef ts As TimeSpan) As Boolean
50 Return Not Equals(ts)
51 End Function
52
53 Function Operator> (ByRef ts As TimeSpan) As Boolean
54 If CompareTo(ts) > 0 Then
55 Return True
56 Else
57 Return False
58 End If
59 End Function
60
61 Function Operator< (ByRef ts As TimeSpan) As Boolean
62 If CompareTo(ts) < 0 Then
63 Return True
64 Else
65 Return False
66 End If
67 End Function
68
69 Function Operator>= (ByRef ts As TimeSpan) As Boolean
70 If CompareTo(ts) => 0 Then
71 Return True
72 Else
73 Return False
74 End If
75 End Function
76
77 Function Operator<= (ByRef ts As TimeSpan) As Boolean
78 If CompareTo(ts) <= 0 Then
79 Return True
80 Else
81 Return False
82 End If
83 End Function
84
85 'Public Properties
86 Function Ticks() As Int64
87 Return m_Time
88 End Function
89
90 Function Milliseconds() As Long
91 Return (m_Time \ TicksPerMillisecond Mod 1000) As Long
92 End Function
93
94 Function Seconds() As Long
95 Return (m_Time \ TicksPerSecond Mod 60) As Long
96 End Function
97
98 Function Minutes() As Long
99 Return (m_Time \ TicksPerMinute Mod 60) As Long
100 End Function
101
102 Function Hours() As Long
103 Return (m_Time \ TicksPerHour Mod 24) As Long
104 End Function
105
106 Function Days() As Long
107 Return (m_Time \ TicksPerDay) As Long
108 End Function
109
110 Function TotalMilliseconds() As Double
111 Return m_Time / TicksPerMillisecond
112 End Function
113
114 Function TotalSeconds() As Double
115 Return m_Time / TicksPerSecond
116 End Function
117
118 Function TotalMinute() As Double
119 Return m_Time / TicksPerMinute
120 End Function
121
122 Function TotalHours() As Double
123 Return m_Time / TicksPerHour
124 End Function
125
126 Function TotalDays() As Double
127 Return m_Time / TicksPerDay
128 End Function
129
130 Function Add(ByRef ts As TimeSpan) As TimeSpan
131 Return FromTicks(m_Time + ts.m_Time)
132 End Function
133
134 Static Function Compare(ByRef ts1 As TimeSpan, ByRef ts2 As TimeSpan) As Long
135 If ts1.m_Time < ts2.m_Time Then
136 Return -1
137 ElseIf ts1.m_Time = ts2.m_Time Then
138 Return 0
139 ElseIf ts1.m_Time > ts2.m_Time Then
140 Return 1
141 End If
142 End Function
143
144 Function CompareTo(ByRef ts As TimeSpan) As Long
145 Return (m_Time - ts.m_Time) As Long
146 End Function
147
148 Function Duration() As TimeSpan
149 Return FromTicks(Math.Abs(m_Time))
150 End Function
151
152 Function Equals(ByRef ts As TimeSpan) As Boolean
153 Return Equals(This, ts)
154 End Function
155
156 Static Function Equals(ByRef ts1 As TimeSpan, ByRef ts2 As TimeSpan) As Boolean
157 If ts1.m_Time = ts2.m_Time Then
158 Return True
159 Else
160 Return False
161 End If
162 End Function
163
164 Static Function FromTicks(ticks As Int64) As TimeSpan
165 If (ticks > MaxValue) Or (ticks < MinValue) Then
166 'ArgumentOutOfRangeException
167 debug
168 Exit Function
169 End If
170 FromTicks.m_Time = ticks
171 End Function
172
173 Static Function FromMilliseconds(value As Double) As TimeSpan
174 Return FromTicks((value * TicksPerMillisecond) As Int64)
175 End Function
176
177 Static Function FromSeconds(value As Double) As TimeSpan
178 Return FromTicks((value * TicksPerSecond)As Int64)
179 End Function
180
181 Static Function FromMinutes(value As Double) As TimeSpan
182 Return FromTicks((value * TicksPerMinute) As Int64)
183 End Function
184
185 Static Function FromHours(value As Double) As TimeSpan
186 Return FromTicks((value * TicksPerHour) As Int64)
187 End Function
188
189 Static Function FromDays(value As Double) As TimeSpan
190 Return FromTicks((value * TicksPerDay) As Int64)
191 End Function
192
193 Function Negate() As TimeSpan
194 Return FromTicks(m_Time * (-1))
195 End Function
196
197 Function Subtract(ByRef ts As TimeSpan) As TimeSpan
198 Return FromTicks(m_Time - ts.m_Time)
199 End Function
200End Class
Note: See TracBrowser for help on using the repository browser.