I've imported momentjs properly. It's working fine, but when I go to try to import moment-timezone, I can't get it to work. I don't have access to any functions.
Here's my aurelia.json file where I'm loading them from npm:
{
"name": "moment",
"path": "../node_modules/moment",
"main": "moment",
"exports": "moment"
},
{
"name": "moment-timezone",
"path": "../node_modules/moment-timezone",
"main": "moment-timezone",
"deps": [ "moment" ],
"exports": "tz"
}
and here's where I'm trying to load them into the file:
import { autoinject } from "aurelia-framework";
import * as moment from "moment";
import * as tz from "moment-timezone";
@autoinject
export class GlobalUtil {
}
Is this the right way to load them? It's not working for me unfortunately.
Now when I try to specify a timezone, I get a "Moment Timezone has no data for America/New_York." Then it console.logs(7am), which is not the correct time.
Maybe I can help a bit with this. In order to give decent instructions, I'll add step-by-step instructions for the entire chain of adding moment/moment-timezone to an Aurelia CLI app.
Install moment.js
npm install --save moment
typings install dt~moment --global --save
Install moment-timezone
npm install --save moment-timezone
typings install dt~moment-timezone --global --save
Next, configure both in the "dependencies" section of aurelia.json:
Finally, let's wrap this up with a simple example on how to actually use this:
That should be it! So far so good, at least for the configuration part. But, as your question already indicates, you may receive an error in the trend of:
This means that, by default, moment-timezone has no knowledge of that specific timezone. As the link from the error message mentions, you have to add it yourself. For example like:
Add as much timezones as you'd like to this array. Or download/use a predefined bundle from the momentjs website (see link above).
Hope this helps!