-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($time): create time service #10525
base: master
Are you sure you want to change the base?
Conversation
CLAs look good, thanks! |
how is this different from https://docs.angularjs.org/api/ngMock/type/angular.mock.TzDate ? |
TzDate is great for testing, but I think we could use $time to move some logic from the date filter and date input handlers into a more logical and re-usable place, which is why I said it would be nice to do it |
src/ng/time.js
Outdated
var self = this; | ||
|
||
this.$get = ['$window', function($window) { | ||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think that there will be more properties added to $time
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that just returning a function would be better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually return function - the doc was wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning $window.Date.now
rather than an object would actually make mocking harder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The options we have here:
// 1
this.now = $window.Date.now;
// 2
this.now = function() {
return new Date();
};
- Was requested in $time service #10402 and is implemented in PR
- Is what what you @caitp call object? I've build something like this in my project, and it worked nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think that $time
should be a function (that is a wrap that calls $window.Date()
), just like what we have for $timeout
. Mocks can be done in the same way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's problematic if we do want to put functionality for date filter/date input on it, because those then become harder to mock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With $timeout
we just wrap one function inside the other. Here I can imaging that later we will want to have other properties. $time.now()
is easier to extend, $time()
seems only to be a bit shorter. And it should be called $now then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's problematic if we do want to put functionality for date filter/date input on it, because those then become harder to mock.
why is this different than $timeout
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$timeout only has one custom method to mock, we'd potentially have 3, possibly more
@caitp I think you are right, this would be a good addition |
3959c66
to
cc054db
Compare
why not |
@gdi2290 |
Add simple $time service to allow easier mocking dates in applications. Closes angular#10402
@lgalfaso - do you have some sugestions about tests? I feel that the current one are not really valuable. |
@manuel-woelker sorry for the late response. Even when the PR looks good if we are just looking at the core, I think it is important that there is a reasonable counterpart for ng-mock. This is going to take a little bit more time to get done right, but I would still would like to aim at 1.4 |
Could you provide example of what should this ng-mock counterpart do? I can think only of some $date.setTime(), but this can be acomplished by just mocking the normal fuction |
Here is the first draft
|
Ah, that looks like a pretty big change. Is there separate ticket for that? There is #10402, but it's defined much simpler. btw
should this be something like So the queue will know that there should be two intervals fired before timeout? |
yes, and also that |
This should land in 1.5 - @lgalfaso can you manage it? |
I will take care |
@@ -80,6 +80,7 @@ | |||
$TemplateCacheProvider, | |||
$TemplateRequestProvider, | |||
$$TestabilityProvider, | |||
$TimeProvider, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be $DateProvider
?
@lgalfaso, I am kind of confused. Is there some followup planned with more features ? From the discussion above, I got the impression this would be more feature-rich/involved. |
When I said "this should land", I hadn't actually reviewed this, by the way ;-P |
Let me revert this |
Wait...whaat ?! We should actually review the PRs before LGTM'ing ? 😛 |
'This Should Land In One Point Five' (TSLIOPF) does not start with the letters L.G.T.M, as far as I can tell. |
@lgalfaso - we probably don't need a revert just a bit of additional polish, right? |
reverted this with 7dcfe5e |
Add simple $time service to allow easier mocking dates in applications.
Closes #10402