Changeset 107 for Include/Classes


Ignore:
Timestamp:
Feb 17, 2007, 6:41:00 PM (18 years ago)
Author:
OverTaker
Message:

TimeSpanに伴う変更と、Addメソッドの仕様変更。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Include/Classes/System/DateTime.ab

    r103 r107  
    2727        End If
    2828        DateTime(316224000000000)
    29         AddYears(year - 1)
     29        This = AddYears(year - 1)
    3030
    3131        Dim days As Long
     
    3535        Next
    3636        days += day
    37         AddDays(days - 1)
     37        This = AddDays(days - 1)
    3838    End Sub
    3939
     
    4949        End If
    5050        DateTime(year, month, day)
    51         AddHours(hour)
    52         AddMinutes(minute)
    53         AddSeconds(second)
     51        This = AddHours(hour)
     52        This = AddMinutes(minute)
     53        This = AddSeconds(second)
    5454    End Sub
    5555
     
    6161    Sub DateTime(year As Long, month As Long, day As Long, hour As Long, minute As Long, second As Long, millisecond As Long)
    6262        DateTime(year, month, day, hour, minute, second)
    63         AddMilliseconds(millisecond)
     63        This = AddMilliseconds(millisecond)
    6464    End Sub
    6565
     
    8484    Sub ~DateTime()
    8585    End Sub
     86
     87    Function Operator+ (ByRef value As TimeSpan) As DateTime
     88        Dim date As DateTime(Ticks + value.Ticks)
     89        Return date
     90    End Function
     91
     92    Function Operator- (ByRef value As DateTime) As TimeSpan
     93        Return TimeSpan.FromTicks(Ticks - value.Ticks)
     94    End Function
     95
     96    Function Operator- (ByRef value As TimeSpan) As DateTime
     97        Dim date As DateTime(Ticks - value.Ticks)
     98        Return date
     99    End Function
    86100
    87101    Function Operator == (ByRef value As DateTime) As Boolean
     
    131145
    132146    Function Millisecond() As Long
    133         Return (Ticks \ 10000 Mod 1000) As Long
     147        Return (Ticks \ TimeSpan.TicksPerMillisecond Mod 1000) As Long
    134148    End Function
    135149
    136150    Function Second() As Long
    137         Return (Ticks \ 10000000 Mod 60) As Long
     151        Return (Ticks \ TimeSpan.TicksPerSecond Mod 60) As Long
    138152    End Function
    139153
    140154    Function Minute() As Long
    141         Return (Ticks \ 600000000 Mod 60) As Long
     155        Return (Ticks \ TimeSpan.TicksPerMinute Mod 60) As Long
    142156    End Function
    143157
    144158    Function Hour() As Long
    145         Return (Ticks \ 36000000000 Mod 24) As Long
     159        Return (Ticks \ TimeSpan.TicksPerHour Mod 24) As Long
    146160    End Function
    147161
     
    177191    End Function
    178192
    179     Function DayOfWeek() As DayOfWeek
     193    Function DayOfWeek() As Long
    180194        Return totalDays() Mod 7 - 1
    181195    End Function
     
    238252    End Function
    239253
    240     Sub AddTicks(value As Int64)
     254    Function Add(ByRef value As TimeSpan) As DateTime
     255        Return This + value
     256    End Function
     257
     258    Function AddTicks(value As Int64) As DateTime
    241259        Dim ticks As Int64
    242260        ticks = Ticks
    243         If (ticks > DateTime.MaxValue - value) Or (ticks < DateTime.MinValue - value) Then
     261        If (ticks > MaxValue - value) Or (ticks < MinValue - value) Then
    244262            'ArgumentOutOfRangeException
    245263            debug
    246264        End If
    247         Ticks = ticks + value
    248     End Sub
    249 
    250     Sub AddMilliseconds(value As Double)
    251         AddTicks((value * 10000) As Int64)
    252     End Sub
    253 
    254     Sub AddSeconds(value As Double)
    255         AddTicks((value * 10000000) As Int64)
    256     End Sub
    257 
    258     Sub AddMinutes(value As Double)
    259         AddTicks((value * 600000000) As Int64)
    260     End Sub
    261 
    262     Sub AddHours(value As Double)
    263         AddTicks((value * 36000000000) As Int64)
    264     End Sub
    265 
    266     Sub AddDays(value As Double)
    267         AddTicks((value * 864000000000) As Int64)
    268     End Sub
    269 
    270     Sub AddYears(value As Double)
     265
     266        AddTicks.Ticks = ticks + value
     267        AddTicks.Kind = Kind
     268    End Function
     269
     270    Function AddMilliseconds(value As Double) As DateTime
     271        Return AddTicks((value * TimeSpan.TicksPerMillisecond) As Int64)
     272    End Function
     273
     274    Function AddSeconds(value As Double) As DateTime
     275        Return AddTicks((value * TimeSpan.TicksPerSecond) As Int64)
     276    End Function
     277
     278    Function AddMinutes(value As Double) As DateTime
     279        Return AddTicks((value * TimeSpan.TicksPerMinute) As Int64)
     280    End Function
     281
     282    Function AddHours(value As Double) As DateTime
     283        Return AddTicks((value * TimeSpan.TicksPerHour) As Int64)
     284    End Function
     285
     286    Function AddDays(value As Double) As DateTime
     287        Return AddTicks((value * TimeSpan.TicksPerDay) As Int64)
     288    End Function
     289
     290    Function AddYears(value As Double) As DateTime
    271291        Dim year As Long
    272292        Dim intValue As Long
     293        Dim ticks As Int64
    273294        year = Year
    274295        intValue = Int(value)
    275         AddTicks(intValue * 315360000000000 + 864000000000 * ((year Mod 4 + intValue) \ 4 - (year Mod 100 + intValue) \ 100 + (year Mod 400 + intValue) \ 400))
     296        ticks = Ticks + intValue * 315360000000000 + 864000000000 * ((year Mod 4 + intValue) \ 4 - (year Mod 100 + intValue) \ 100 + (year Mod 400 + intValue) \ 400)
     297
    276298        If value < 0 Then
    277299            If (year Mod 4 + intValue <= 0 And year Mod 100 > 4) Or (year Mod 400 <= 4) Then
    278                 AddTicks(-864000000000)
     300                ticks -= 864000000000
    279301            End If
    280302        End If
    281 
    282303        If IsLeapYear(year) = TRUE Then
    283             AddTicks(((value - intValue) * 316224000000000) As Int64)
    284         Else
    285             AddTicks(((value - intValue) * 315360000000000) As Int64)
    286         End If
    287     End Sub
     304            ticks += (value - intValue) * 316224000000000
     305        Else
     306            ticks += (value - intValue) * 315360000000000
     307        End If
     308       
     309        AddYears.Ticks = ticks
     310        AddYears.Kind = Kind
     311    End Function
     312
     313    Function Subtract(ByRef value As DateTime) As TimeSpan
     314        Return This - value
     315    End Function
     316
     317    Function Subtract(ByRef value As TimeSpan) As DateTime
     318        Return This - value
     319    End Function
    288320
    289321    Static Function DaysInMonth(year As Long, month As Long) As Long
     
    430462
    431463    Function totalDays() As Long
    432         Return (Ticks \ 864000000000) As Long
     464        Return (Ticks \ TimeSpan.TicksPerDay) As Long
    433465    End Function
    434466
Note: See TracChangeset for help on using the changeset viewer.