Giter Site home page Giter Site logo

Comments (7)

yjbanov avatar yjbanov commented on August 17, 2024

What we probably need is for Clock to be callable, so you could do:

clock().subtract(duration);

With this in place we could easily get rid of agoBy and fromNowBy.

There is some level of intentional redundancy in the API, e.g.:

clock.ago(days: 1);
clock.daysAgo(1);

*Ago and *FromNow are not strictly necessary. They are there for convenience only. For example, it is less code to pass weeksAgo function to other functions:

// Same day of week for the next 7 weeks
new List.generate(7, clock.weeksFromNow);

from quiver-dart.

seaneagan avatar seaneagan commented on August 17, 2024

+1 to making Clock callable.

I think in most scenarios you are going to have to access the clock a single time, and pass the result around, otherwise the dates will all be off by a few milliseconds or so. I think that example would likely have to be:

var now = clock();
new List.generate(7, (i) => now.add(aWeek * i));

from quiver-dart.

yjbanov avatar yjbanov commented on August 17, 2024

Is the existence of these extra methods causing problems?

from quiver-dart.

seaneagan avatar seaneagan commented on August 17, 2024

Not at all. The reason I brought it up is I would like to see Clock in dart:core someday to support:

http://dartbug.com/16762

and that Clock would likely have very few methods. If that ever happened, then quiver's Clock would likely be deprecated, and not having the extra methods would make that transition a bit easier.

from quiver-dart.

seaneagan avatar seaneagan commented on August 17, 2024

Could use top-level functions to allow defaulting to the system clock:

ago(Duration duration, [Clock clock = const Clock.system()]) => 
    clock.now().subtract(duration);
fromNow(Duration duration, [Clock clock = const Clock.system()]) => 
    clock.now().add(duration);

Then in scripts or whatever that don't need to have their time mocked, can just do:

fromNow(anHour)
ago(aDay)

Also regarding Clock potentially moving to dart:core in the future, see:

https://code.google.com/p/dart/issues/detail?id=18149

from quiver-dart.

yjbanov avatar yjbanov commented on August 17, 2024

I agree. I'm ok with keeping this issue open, but I don't think we should be making any changes until something actually happens in the SDK.

from quiver-dart.

cbracken avatar cbracken commented on August 17, 2024

Closing as stale. This class is so heavily used internally that changing these APIs at this point that the benefit outweighs the cost. As mentioned elsewhere, I've always been a fan of offsetBy(Duration) or at least offsetBy({years, weeks, days, ...}) but I'm not sure we'll find many people keen to sign up for the thousands of patches we'd need to land to migrate :-)

from quiver-dart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.