-
Notifications
You must be signed in to change notification settings - Fork 397
amMomentConfig.timezone
has no effect
#271
Comments
It should be handled by |
Sounds good, but this.preprocessDate = function (value) {
// Configure the default timezone if needed
if (defaultTimezone !== angularMomentConfig.timezone) {
this.changeTimezone(angularMomentConfig.timezone);
}
if (angularMomentConfig.preprocess) {
return angularMomentConfig.preprocess(value);
}
if (!isNaN(parseFloat(value)) && isFinite(value)) {
// Milliseconds since the epoch
return moment(parseInt(value, 10));
}
// else just returns the value as-is.
return moment(value);
}; There is a call to For contrast, here's how this.applyTimezone = function (aMoment, timezone) {
timezone = timezone || angularMomentConfig.timezone;
if (!timezone) {
return aMoment;
}
if (timezone.match(/^Z|[+-]\d\d:?\d\d$/i)) {
aMoment = aMoment.utcOffset(timezone);
} else if (aMoment.tz) {
aMoment = aMoment.tz(timezone);
} else {
$log.warn('angular-moment: named timezone specified but moment.tz() is undefined. Did you forget to include moment-timezone.js?');
}
return aMoment;
}; You can clearly see the default timezone retrieved at the top, and then the call to All of my dates in my app are displaying in UTC instead of the configured timezone. Am I missing something? |
I can sure try. Let's see what I can come up with. |
Thank you! |
Here's a failing test. It passes on 0.10.3 it('should apply the configured timezone to moment objects', function () {
angularMomentConfig.timezone = 'Pacific/Tahiti';
var timestamp = moment.tz('2012-01-22T12:46:54Z', 'UTC');
expect(amDateFormat(timestamp, '(HH,mm,ss);MM.DD.YYYY')).toBe('(02,46,54);01.22.2012');
}); It's just like this one, except it uses a moment object instead of a JS Date. it('should respect the configured timezone', function () {
angularMomentConfig.timezone = 'Pacific/Tahiti';
var timestamp = Date.UTC(2012, 0, 22, 12, 46, 54);
expect(amDateFormat(timestamp, '(HH,mm,ss);MM.DD.YYYY')).toBe('(02,46,54);01.22.2012');
}); |
Spot on! Any chance you can create a PR with this test case and the fix? |
I'm not sure I have the background to do so. In 0.10.3, there is the |
Actually, it is a little tricky. In 0.10.3, I believe that the best solution would just be to stop using |
Ahh, see that's not that simple for me either. All of my dates come down from the server in UTC so are parsed in moment as having a UTC timezone. I want them to stay in UTC while doing processing, but I was using I understand your reasoning, but this was my main reason for including |
Hmm... Depending on what you actually do when processing, the timezone may not have any effect there anyway. But if you wanted to achieve a pre-1.0.0 behavior, and don't need to override the timezone in specific cases with
|
Not a bad idea. I'm signing off of work for today, so I'll check on this tomorrow. It might be the right thing for my project. You still might want to consider removing the timezone option if it no longer affects amDateFormat, which is what the readme says it does now:
The other thing you might be able to do is hang an extra attribute on the moment object (ex: |
Thanks for the suggestions, I think updating the docs to reflect this would make more sense. Hanging an extra attribute on the moment object sounds like "too much magic" for me, and there will probably be some corner cases, etc. |
I agree that splitting things up into multiple compossible filters made the project less complicated and more approachable, but it does seem like we've lost some important functionality here. It used to be that you could set a default display timezone for your whole project, and then it would be used, unless you specifically overrode it in A related question: If the |
Does the problem is solved @CyborgMaster ? |
Not really. I had to use the preprocess function suggested by @urish, so I'm hard coded to one timezone per browser instance. |
I just ran into this issue as well. It's a shame that the constant is no longer working. +1 |
I just upgraded to 1.0.0 and
amMomentConfig.timezone
doesn't seem to do anything anymore.It used to be that the following would always display in the set timezone:
Now it appears that
amDateFormat
doesn't apply any timezone shifting. Am I missing something?amDateFormat
used to run the following in version 0.10.3now it skips
applyTimezone
which is what converted it to the default timezone and simple returns this:Is there some new way to set up the default timezone, or make sure it gets applied correctly?
The text was updated successfully, but these errors were encountered: