Skip to content

[Proposal] Add DateTime.addYears, DateTime.addMonths, DateTime.addDays, ... #27245

Open
@jolleekin

Description

@jolleekin

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

  1. There's no easy way to add years to a DateTime
  2. There's no easy way to add months to a DateTime
  3. There's no easy way to subtract years from a DateTime
  4. There's no easy way to subtract months from a DateTime
  5. There's no easy way to subtract a DateTime from another
  6. 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
  7. Using Duration is more cumbersome than int or num

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.core-2library-coretype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions