0

我有一个客户在西海岸,但想查看基于东海岸时间(美国/纽约)的信息。

我正在尝试使用 WallTime 库:https ://github.com/sproutsocial/walltime-js

define(function(require) {

var _ = require('underscore'),
    Backbone = require('backbone'),
    WallTime = require('walltime');
require('backbone.relational');
require('walltime-data');


var DateRange = Backbone.RelationalModel.extend({
    initialize: function(opts) {

        var self = this,
            type = (opts && opts.type) || "today";

        if(type == "custom") {
            var undef = _.isUndefined(opts.start) && _.isUndefined(opts.end);

            if(undef)
                throw "'start' and/or 'end' date not present in options for type: custom";
        }

        function getNycDate(date){
            var someUTCDate = new Date(date.getTime()),
            nycWallTime = WallTime.UTCToWallTime(someUTCDate, "America/New_York");
            return nycWallTime;
        }

        function setup() {
            var now = getNycDate(new Date());
        }
     }
   }
}

尝试计算 walltime 时出现以下错误:未捕获的错误:必须在设置时区之前使用规则和区域调用 init

4

1 回答 1

0

当您在加载您的时区数据之前尝试初始化 WallTime 时,会发生这种情况。首先重新排序您的要求语句和/或要求时区数据。

资料来源:我是 SproutSocial 开发人员。

于 2014-03-12T12:56:49.537 回答