Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a Date manipulation library #5627

Open
floitschG opened this issue Oct 3, 2012 · 6 comments
Open

Provide a Date manipulation library #5627

floitschG opened this issue Oct 3, 2012 · 6 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. core-2 P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@floitschG
Copy link
Contributor

Currently there is no good way to manipulate dates.
For example there is no good way to produce recurring dates (daily, weekly or monthly). Even worse, the intuitive approach is often wrong: date.add(new Duration(days: 1)) will not work on dates where daylight-saving is changed (going from summer to winter time or the inverse).

Ideally there should be a library that allows to easily deal with such common tasks.

@floitschG
Copy link
Contributor Author

Some methods that should be in this calendar library.

* what's the last day of this month (typically "first of next month - 1")

  • today + 1 day
  • today + 1 week
  • what's the date one week from now
  • what's the date N minutes from now (is it still today?)
  • when was the last Sunday
  • when is the next Saturday?
  • When does a week start?

@DartBot
Copy link

DartBot commented Apr 19, 2013

This comment was originally written by @seaneagan


It would be awesome if this library could be on github! I would love to
contribute.


I think a time unit enum would be useful for a lot of these APIs:

enum TimeUnit SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR;

Example APIs:

DateTime floor(DateTime dt, TimeUnit unit);
DateTime ceil(DateTime dt, TimeUnit unit);
DateTime addTimeUnits(DateTime dt, TimeUnit unit, [int count = 1]);

(of course they could be instance methods on DateTime if TimeUnit were in
dart:core)

Usage:

var now = new DateTime.now();

var startOfDay = floor(now, TimeUnit.DAY); // see issue #10003
var startOfWeek = floor(now, TimeUnit.WEEK);
var endOfMonth = ceil(now, TimeUnit.MONTH);
var inOneDay = addTimeUnits(now, TimeUnit.DAY);
var inOneWeek = addTimeUnits(now, TimeUnit.WEEK);

@DartBot
Copy link

DartBot commented Feb 4, 2014

This comment was originally written by wshadd...@gmail.com


I'd like to also request that a method to return the week # would be great. Possibly just implementing the ISO 8601 standard or giving the option to using Jan 1st as the first week.

Details of the algorithm in javascript can be found at http://techblog.procurios.nl/k/news/view/33796/14863/calculate-iso-8601-week-and-year-in-javascript.html

@DartBot
Copy link

DartBot commented Feb 4, 2014

This comment was originally written by wsh...@gmail.com


I'm just now learning the dart language so here is my first attempt at translating the javascript code to dart. Not optimized and probably buggy, but the couple of spot tests I ran seemed ok.

https://gist.github.com/wshaddix/8797934

@floitschG floitschG added Type-Enhancement area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Feb 4, 2014
@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug and removed triaged labels Feb 29, 2016
@lrhn lrhn added the core-m label Aug 11, 2017
@floitschG floitschG added core-2 and removed core-m labels Aug 29, 2017
@dnfield
Copy link
Contributor

dnfield commented Feb 9, 2018

I have some needs around this and have started an implementation of a Calendar/GregorianCalendar. https://github.com/dnfield/dart_calendar on pub as date_calendar

@svenjacobs
Copy link

Maybe also related to #33014? Functionality similar to Joda Time (in Java) or moment.js (in JavaScript) greatly appreciated :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. core-2 P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants