1  Namespace System


2 


3 


4  Class TimeSpan


5  m_Time As Int64


6  Public


7  Static MaxValue = 3162240000000000000 As Int64


8  Static MinValue = 3162240000000000000 As Int64


9  Static TicksPerDay = 864000000000 As Int64


10  Static TicksPerHour = 36000000000 As Int64


11  Static TicksPerMinute = 600000000 As Int64


12  Static TicksPerSecond = 10000000 As Int64


13  Static TicksPerMillisecond = 10000 As Int64


14  Static Zero = 0 As Int64


15 


16  Sub TimeSpan(ticks As Int64)


17  If (ticks > MaxValue) Or (ticks < MinValue) Then


18  'ArgumentOutOfRangeException


19  debug


20  Exit Sub


21  End If


22  m_Time = ticks


23  End Sub


24 


25  Sub TimeSpan(ts As TimeSpan)


26  m_Time = ts.m_Time


27  End Sub


28 


29  Sub ~TimeSpan()


30  End Sub


31 


32  Function Operator+ (ts As TimeSpan) As TimeSpan


33  Return FromTicks(m_Time + ts.m_Time)


34  End Function


35 


36  Function Operator (ts As TimeSpan) As TimeSpan


37  Return FromTicks(m_Time  ts.m_Time)


38  End Function


39 


40  Function Operator* (value As Long) As TimeSpan


41  Return FromTicks(m_Time * value)


42  End Function


43 


44  Function Operator/ (value As Long) As TimeSpan


45  Return FromTicks(m_Time \ value)


46  End Function


47 


48  Function Operator== (ts As TimeSpan) As Boolean


49  Return Equals(ts)


50  End Function


51 


52  Function Operator<> (ts As TimeSpan) As Boolean


53  Return Not Equals(ts)


54  End Function


55 


56  Function Operator> (ts As TimeSpan) As Boolean


57  If CompareTo(ts) > 0 Then


58  Return True


59  Else


60  Return False


61  End If


62  End Function


63 


64  Function Operator< (ts As TimeSpan) As Boolean


65  If CompareTo(ts) < 0 Then


66  Return True


67  Else


68  Return False


69  End If


70  End Function


71 


72  Function Operator>= (ts As TimeSpan) As Boolean


73  If CompareTo(ts) => 0 Then


74  Return True


75  Else


76  Return False


77  End If


78  End Function


79 


80  Function Operator<= (ts As TimeSpan) As Boolean


81  If CompareTo(ts) <= 0 Then


82  Return True


83  Else


84  Return False


85  End If


86  End Function


87 


88  'Public Properties


89  Function Ticks() As Int64


90  Return m_Time


91  End Function


92 


93  Function Milliseconds() As Long


94  Return (m_Time \ TicksPerMillisecond Mod 1000) As Long


95  End Function


96 


97  Function Seconds() As Long


98  Return (m_Time \ TicksPerSecond Mod 60) As Long


99  End Function


100 


101  Function Minutes() As Long


102  Return (m_Time \ TicksPerMinute Mod 60) As Long


103  End Function


104 


105  Function Hours() As Long


106  Return (m_Time \ TicksPerHour Mod 24) As Long


107  End Function


108 


109  Function Days() As Long


110  Return (m_Time \ TicksPerDay) As Long


111  End Function


112 


113  Function TotalMilliseconds() As Double


114  Return m_Time / TicksPerMillisecond


115  End Function


116 


117  Function TotalSeconds() As Double


118  Return m_Time / TicksPerSecond


119  End Function


120 


121  Function TotalMinute() As Double


122  Return m_Time / TicksPerMinute


123  End Function


124 


125  Function TotalHours() As Double


126  Return m_Time / TicksPerHour


127  End Function


128 


129  Function TotalDays() As Double


130  Return m_Time / TicksPerDay


131  End Function


132 


133  Function Add(ts As TimeSpan) As TimeSpan


134  Return FromTicks(m_Time + ts.m_Time)


135  End Function


136 


137  Static Function Compare(ts1 As TimeSpan, ts2 As TimeSpan) As Long


138  If ts1.m_Time < ts2.m_Time Then


139  Return 1


140  ElseIf ts1.m_Time = ts2.m_Time Then


141  Return 0


142  ElseIf ts1.m_Time > ts2.m_Time Then


143  Return 1


144  End If


145  End Function


146 


147  Function CompareTo(ts As TimeSpan) As Long


148  Return (m_Time  ts.m_Time) As Long


149  End Function


150 


151  Function Duration() As TimeSpan


152  Return FromTicks(System.Math.Abs(m_Time))


153  End Function


154 


155  Function Equals(ts As TimeSpan) As Boolean


156  Return Equals(This, ts)


157  End Function


158 


159  Static Function Equals(ts1 As TimeSpan, ts2 As TimeSpan) As Boolean


160  If ts1.m_Time = ts2.m_Time Then


161  Return True


162  Else


163  Return False


164  End If


165  End Function


166 


167  Static Function FromTicks(ticks As Int64) As TimeSpan


168  If (ticks > MaxValue) Or (ticks < MinValue) Then


169  'ArgumentOutOfRangeException


170  debug


171  Exit Function


172  End If


173  Return New TimeSpan( ticks )


174  End Function


175 


176  Static Function FromMilliseconds(value As Double) As TimeSpan


177  Return FromTicks((value * TicksPerMillisecond) As Int64)


178  End Function


179 


180  Static Function FromSeconds(value As Double) As TimeSpan


181  Return FromTicks((value * TicksPerSecond)As Int64)


182  End Function


183 


184  Static Function FromMinutes(value As Double) As TimeSpan


185  Return FromTicks((value * TicksPerMinute) As Int64)


186  End Function


187 


188  Static Function FromHours(value As Double) As TimeSpan


189  Return FromTicks((value * TicksPerHour) As Int64)


190  End Function


191 


192  Static Function FromDays(value As Double) As TimeSpan


193  Return FromTicks((value * TicksPerDay) As Int64)


194  End Function


195 


196  Function Negate() As TimeSpan


197  Return FromTicks(m_Time * (1))


198  End Function


199 


200  Function Subtract(ts As TimeSpan) As TimeSpan


201  Return FromTicks(m_Time  ts.m_Time)


202  End Function


203  End Class


204 


205 


206  End Namespace

