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

Feature/timezone support #27

Merged
merged 3 commits into from
Dec 30, 2013
Merged

Conversation

kayhadrin
Copy link
Contributor

Summary

Hi there,

With this pull request, I'm proposing to add moment-timezone support.

This would allow the amCalendar and amDateFormat filters to display dates aligned to a different timezone instead of the local machine's.

How?

To configure this, a new angularMomentConfig constant was created as follow:

angularMoment.constant('angularMomentConfig', {
    timezone: '' // e.g. 'Europe/London'
})

I took also the initiative to regroup the code inside a closure to:

  • define the applyTimezone private function
  • optimise the 'use strict' definition

Usage example

HTML

<script src="components/moment/moment.js"></script>
<script src="components/moment-timezone/moment-timezone.js"></script>
<!-- Visit momentjs.com/timezone/data/ to obtain your own timezone data -->
<script src="your_own/moment-timezone-data.js"></script>
<script src="components/angular-moment/angular-moment.js"></script>

<!-- 
    For a message.time = new Date('2013-10-07T00:00:00.000Z') 
    and angularMomentConfig.timezone = 'Australia/Sydney'
-->

<span>{{message.time | amDateFormat:'dddd, MMMM Do YYYY, h:mm:ss a'}}</span>

<!-- This snippet will format the given time as "Monday, October 7th 2013, 11:00:00 am". -->

Javascript

var myapp = angular.module('myapp', ['angularMoment']);

myapp.controller('app', [
    'angularMomentConfig',
    function (angularMomentConfig) {
        angularMomentConfig.timezone = 'Australia/Sydney';
    }
]);

David Han Sze Chuen added 3 commits December 31, 2013 01:22
- add new config var: angularMomentConfig
- optimise the 'use strict' definition
@kayhadrin
Copy link
Contributor Author

It's a late here, but I can try to implement some test cases for it later if you are interested.

urish added a commit that referenced this pull request Dec 30, 2013
@urish urish merged commit deef3cc into urish:master Dec 30, 2013
@urish
Copy link
Owner

urish commented Dec 30, 2013

Many thanks! can you please add some tests cases as well?

That'd be awesome :-)

@urish
Copy link
Owner

urish commented Jan 31, 2014

Released at 0.6.1

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 this pull request may close these issues.

None yet

2 participants