Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Can timezone be non-constant? #92

Closed
hoopes opened this issue Oct 24, 2014 · 15 comments
Closed

Can timezone be non-constant? #92

hoopes opened this issue Oct 24, 2014 · 15 comments

Comments

@hoopes
Copy link

hoopes commented Oct 24, 2014

I'd really like the option of being able to switch timezone dynamically. Is that an option? Any guidance for your preferred implementation of that (if I were to find some time to do it)?

@akarl
Copy link

akarl commented Oct 30, 2014

Came here for this.

How about the possibility to set the timezone as a function?

this.applyTimezone = function (aMoment) {
    var timezone = angularMomentConfig.timezone;

    // Adding this check to be able to set the timezone from a function
    if (typeof timezone === 'function') {
        timezone = timezone();
    }

    if (aMoment && timezone) {
        if (aMoment.tz) {
            aMoment = aMoment.tz(timezone);
        } else {
            $log.warn('angular-moment: timezone specified but moment.tz() is undefined. Did you forget to include moment-timezone.js?');
        }
    }
    return aMoment;
};

I would have time to do a PR if the solution is ok.

@Mathbl
Copy link

Mathbl commented Nov 3, 2014

+1

1 similar comment
@demisx
Copy link

demisx commented Nov 7, 2014

+1

@franleplant
Copy link

+1!

@franleplant
Copy link

When would this be merged?

@urish
Copy link
Owner

urish commented Nov 24, 2014

I believe it would make more sense to expose an API for changing the timezone rather than passing a function here. Something like: amMoment.changeTimezone('UTC');. This alternative seems to be more consistent with the amMoment.changeLocale() API we already have.

Thoughts?

@franleplant
Copy link

@urish your proposal seams cleaner 👍

@akarl
Copy link

akarl commented Nov 25, 2014

@urish I agree, that's a better fix than mine

@vdsabev
Copy link

vdsabev commented Nov 26, 2014

+1, we will be using this

@jirihelmich
Copy link

What about adding an additional param to the format filter? In my app, the timezone is different quite often and there is nothing like default display timezone. I wouldn't configure any and use just those.

For others, the default could stay and this one would override it locally.

@urish
Copy link
Owner

urish commented Dec 10, 2014

Anybody up to creating a PR for the amMoment.changeTimezone() proposal?

Thanks!

@bierdok
Copy link

bierdok commented Jan 22, 2015

+1 for amMoment.changeTimezone([string]) !

@bierdok
Copy link

bierdok commented Jan 22, 2015

it can be useful with this https://github.com/cmmartin/ngTimezone

@bierdok
Copy link

bierdok commented Jan 22, 2015

you can do that

angular
    .module('helloworld.moment', [
        'angularMoment',
        'ngTimezone'
    ]).run(function($timezone, angularMomentConfig) {
        angularMomentConfig.preprocess = 'utc';
        angularMomentConfig.timezone = $timezone.getName();
    });

@urish urish closed this as completed in 4383e73 Jan 22, 2015
@ansonphong
Copy link

I second @jirihelmich - there is no constant time zones in the app I'm building. I need the option to switch the timezone dynamically using a filter.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants