Changeset 263


Ignore:
Timestamp:
May 30, 2007, 9:25:47 PM (17 years ago)
Author:
OverTaker
Message:

#116のバグを修整。

File:
1 edited

Legend:

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

    r246 r263  
    133133
    134134    Function Day() As Long
    135         Return DayOfYear - totalDaysOfMonths(Year, Month - 1)
     135        Return DayOfYear - totalDaysOfMonth(Year, Month - 1)
    136136    End Function
    137137
     
    140140        Dim day = DayOfYear As Long
    141141        Dim i = 1 As Long
    142         While day > totalDaysOfMonths(year, i)
     142        While day > totalDaysOfMonth(year, i)
    143143            i++
    144144        Wend
     
    148148    Function Year() As Long
    149149        Dim day = (Ticks \ TimeSpan.TicksPerDay) As Long
    150         Dim year = Int((day + day \ 36524 - day \ 146097) / 365.25) As Long
    151         If day - totalDaysOfYears(year) + 1 = 366 Then
     150        Dim year = Int((day + day \ 36524 - day \ 146097) / 365.25) + 1 As Long
     151        If day - yearToDay(year - 1) + 1 = 366 Then
    152152            Return year + 1
    153153        Else
     
    157157
    158158    Function DayOfWeek() As Long 'As DayOfWeek
    159         Return ((Ticks \ TimeSpan.TicksPerDay) Mod 7) As Long - 1
     159        Return ((Ticks \ TimeSpan.TicksPerDay) Mod 7) As Long + 1
    160160    End Function
    161161
     
    165165
    166166    Function DayOfYear() As Long
    167         Return ((Ticks \ TimeSpan.TicksPerDay) - totalDaysOfYears(Year) + 1) As Long
     167        Return ((Ticks \ TimeSpan.TicksPerDay) - yearToDay(Year) + 1) As Long
    168168    End Function
    169169
     
    244244
    245245    Function AddYears(value As Double) As DateTime
    246         Dim additionYear = Year + Int(value)
    247         Dim ticks = totalDaysOfYears(additionYear) * TimeSpan.TicksPerDay + DayOfYear() * TimeSpan.TicksPerDay
    248 
    249         If IsLeapYear(additionYear) Then
     246        Dim date = New DateTime(Year + Int(value), Month, Day, Hour, Minute, Second, Millisecond, Kind)
     247        Dim ticks = Ticks _
     248                - (yearToDay(Year) + totalDaysOfMonth(Year, Month - 1) + Day - 1) * TimeSpan.TicksPerDay _
     249                - Hour * TimeSpan.TicksPerHour _
     250                - Minute * TimeSpan.TicksPerMinute _
     251                - Second * TimeSpan.TicksPerSecond _
     252                - Millisecond * TimeSpan.TicksPerMillisecond As Int64
     253        If IsLeapYear(Year + Int(value)) Then
    250254            ticks += (value - Int(value)) * 366 * TimeSpan.TicksPerDay
    251255        Else
    252256            ticks += (value - Int(value)) * 365 * TimeSpan.TicksPerDay
    253257        End If
    254    
    255         Return New DateTime(ticks, Kind)
     258        Return date.AddTicks(ticks)
    256259    End Function
    257260
     
    389392
    390393        initialize(
    391             totalDaysOfYears(year) * TimeSpan.TicksPerDay _
    392             + totalDaysOfMonths(year, month - 1) * TimeSpan.TicksPerDay _
     394            yearToDay(year) * TimeSpan.TicksPerDay _
     395            + totalDaysOfMonth(year, month - 1) * TimeSpan.TicksPerDay _
    393396            + (day - 1) * TimeSpan.TicksPerDay _
    394397            + hour * TimeSpan.TicksPerHour _
     
    446449    End Function
    447450
    448     Static Function totalDaysOfYears(year As Long) As Long
     451    Static Function yearToDay(year As Long) As Long
     452        year--
    449453        Return (Int(year * 365.25) - Int(year * 0.01) + Int(year * 0.0025))
    450454    End Function
    451455
    452     Static Function totalDaysOfMonths(year As Long, month As Long) As Long
     456    Static Function totalDaysOfMonth(year As Long, month As Long) As Long
    453457        Dim days As Long
    454458        Dim i As Long
Note: See TracChangeset for help on using the changeset viewer.