How to import Moment-Timezone with Aurelia / Typescript

I imported the pulses correctly. It works fine, but when I try to import a point in time, I cannot get it to work. I do not have access to any functions.

Here is my aurelia.json file where I download 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 where I try to load them into a file:

import { autoinject } from "aurelia-framework";
import * as moment from "moment";
import * as tz from "moment-timezone";

@autoinject
export class GlobalUtil {

}

Is it right to load them? This does not work for me, unfortunately.

Now, when I try to specify the time zone, I get "Moment Timezone has no data for America / New_York". Then it is console.logs (7am), which does not correspond to the correct time.

+4
source share
1 answer

, . , /- Aurelia CLI.

moment.js

  • npm install --save moment
  • typings install dt~moment --global --save

-

  • npm install --save moment-timezone
  • typings install dt~moment-timezone --global --save

. , TypeScript. , .

"" aurelia.json:

{
    "name": "moment",
    "path": "../node_modules/moment",
    "main": "moment"
},
{
    "name": "moment-timezone",
    "path": "../node_modules/moment-timezone",
    "main": "moment-timezone",
    "deps": ["moment"]
}

, , :

import * as moment from 'moment';
import 'moment-timezone';

export class App {
  message: string;

  constructor() {
    // basic example of using moment().tz
    this.message = moment.tz("2014-06-01 12:00", "Europe/Amsterdam").format();
  }

}

! , , . , , :

Moment Timezone /. . http://momentjs.com/timezone/docs/#/data-loading/

, - . , . , :

moment.tz.add([
    'America/Los_Angeles|PST PDT|80 70|0101|1Lzm0 1zb0 Op0',
    'Europe/Amsterdam|EST EDT|50 40|0101|1Lz50 1zb0 Op0'
]);

, . / - momentjs (. ).

, !

+13

Source: https://habr.com/ru/post/1654349/


All Articles