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

Last change on this file since 271 was 268, checked in by イグトランス (egtra), 17 years ago

StringのResizeを呼ぶコンストラクタでメモリ確保されない場合を排除、ほか微修正

File size: 4.6 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
[268]22 Sub TimeSpan(ts As TimeSpan)
[106]23 m_Time = ts.m_Time
24 End Sub
25
26 Sub ~TimeSpan()
27 End Sub
28
[268]29 Function Operator+ (ts As TimeSpan) As TimeSpan
[106]30 Return FromTicks(m_Time + ts.m_Time)
31 End Function
32
[268]33 Function Operator- (ts As TimeSpan) As TimeSpan
[106]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
[233]42 Return FromTicks(m_Time \ value)
[106]43 End Function
44
[268]45 Function Operator== (ts As TimeSpan) As Boolean
[106]46 Return Equals(ts)
47 End Function
48
[268]49 Function Operator<> (ts As TimeSpan) As Boolean
[106]50 Return Not Equals(ts)
51 End Function
52
[268]53 Function Operator> (ts As TimeSpan) As Boolean
[106]54 If CompareTo(ts) > 0 Then
55 Return True
56 Else
57 Return False
58 End If
59 End Function
60
[268]61 Function Operator< (ts As TimeSpan) As Boolean
[106]62 If CompareTo(ts) < 0 Then
63 Return True
64 Else
65 Return False
66 End If
67 End Function
68
[268]69 Function Operator>= (ts As TimeSpan) As Boolean
[106]70 If CompareTo(ts) => 0 Then
71 Return True
72 Else
73 Return False
74 End If
75 End Function
76
[268]77 Function Operator<= (ts As TimeSpan) As Boolean
[106]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
[268]130 Function Add(ts As TimeSpan) As TimeSpan
[106]131 Return FromTicks(m_Time + ts.m_Time)
132 End Function
133
[268]134 Static Function Compare(ts1 As TimeSpan, ts2 As TimeSpan) As Long
[106]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
[268]144 Function CompareTo(ts As TimeSpan) As Long
[106]145 Return (m_Time - ts.m_Time) As Long
146 End Function
147
148 Function Duration() As TimeSpan
[268]149 Return FromTicks(System.Math.Abs(m_Time))
[106]150 End Function
151
[268]152 Function Equals(ts As TimeSpan) As Boolean
[106]153 Return Equals(This, ts)
154 End Function
155
[268]156 Static Function Equals(ts1 As TimeSpan, ts2 As TimeSpan) As Boolean
[106]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
[265]170 Return New TimeSpan( ticks )
[106]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
[268]197 Function Subtract(ts As TimeSpan) As TimeSpan
[106]198 Return FromTicks(m_Time - ts.m_Time)
199 End Function
200End Class
Note: See TracBrowser for help on using the repository browser.