Comments (7)
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.
+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.
Is the existence of these extra methods causing problems?
from quiver-dart.
Not at all. The reason I brought it up is I would like to see Clock in dart:core someday to support:
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.
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.
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.
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)
- Re-enable dartfmt check when NNBD hints have been removed HOT 1
- Use parameter defaults to specify default MapCache size
- Optional<T> should be Optional<T extends Object> HOT 8
- TreeSet.first/last appear to be returning the same value (in some cases?) HOT 3
- migrate Optional<T> -> "T?" HOT 4
- Suggestion: add "irange", "icount" which would return ints instead of nums HOT 2
- pub.dev shows "Publisher: unverified uploader" HOT 6
- Cache.get's optional ifAbsent parameter should be nullable
- Constant `BiMap` constructor? HOT 1
- Change of Copyright notice HOT 6
- More efficient `isBlank` check (probably)
- Implement a factory constructor on Multimap that copies another Multimap
- Make quiver.collections:DeligatingList mixin DeligatingIterable
- FakeAsync is passing a test after throw UnimplementedError HOT 1
- rename String.isEmpty to isNullOrEmpty HOT 3
- Dart 3: BidirectionalIterator deprecated HOT 1
- Notify when an LRU item is removed HOT 1
- Zip like in Swift HOT 1
- Efficient BiMap cloning
- Fails to build with Dart 3.3.1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quiver-dart.