Open
Description
Problem
It is really inconvenient to work with Dart's DateTime
because it misses some important methods for date-time manipulation. Some good examples are
- There's no easy way to add years to a
DateTime
- There's no easy way to add months to a
DateTime
- There's no easy way to subtract years from a
DateTime
- There's no easy way to subtract months from a
DateTime
- There's no easy way to subtract a
DateTime
from another - I have to deal with low level stuff (leap years; months have different number of days) when I want to do one of the above
- Using
Duration
is more cumbersome thanint
ornum
Proposal
Given the limitations above, I propose adding the following methods to Dart's DateTime
DateTime addDays(num value)
DateTime addHours(num value)
DateTime addMilliseconds(num value)
DateTime addMinutes(num value)
DateTime addMonths(int value)
DateTime addSeconds(num value)
DateTime addTicks(int value)
DateTime addYears(int value)
Duration subtractAnother(DateTime other)
Reference
C#'s DateTime has the following methods
AddDays(Double)
AddHours(Double)
AddMilliseconds(Double)
AddMinutes(Double)
AddMonths(Int32)
AddSeconds(Double)
AddTicks(Int64)
AddYears(Int32)
Subtract(DateTime)