UNPKG

moment-timezone-for-local-time

Version:

Get all matching timezones given a local time and a timestamp. Moment.js plugin

45 lines (42 loc) 1.82 kB
/** * @internal * @see {moment.MomentTimezone.forLocalTime} */ function forLocalTime$1(hour, minute, timestamp) { hour = Math.floor(hour); minute = Math.floor(minute); var tzs = []; var zones = this.names(); for (var _i = 0, zones_1 = zones; _i < zones_1.length; _i++) { var zone = zones_1[_i]; var ref = this(timestamp, zone); if (ref.hour() === hour && ref.minute() === minute) { tzs.push(zone); } } return tzs; } function forLocalTime(hour, minute, timestamp) { if (arguments.length === 0) { var now = new Date(); return forLocalTime$1.call(this, now.getHours(), now.getMinutes(), now.getTime()); } if (timestamp === undefined || timestamp === null) { timestamp = Date.now(); } if (typeof hour !== "number" || 23 < hour || hour < 0) { throw new TypeError("hour arg must be a number and in [0,23]. You gave " + ((hour === null || hour === void 0 ? void 0 : hour.toString()) || "null or undefined") + "."); } if (typeof minute !== "number" || 59 < minute || minute < 0) { throw new TypeError("minute arg must be a number and in [0,59]. You gave " + ((minute === null || minute === void 0 ? void 0 : minute.toString()) || "null or undefined") + "."); } return forLocalTime$1.call(this, hour, minute, timestamp.valueOf()); } function extend(momentJS) { if (!(momentJS === null || momentJS === void 0 ? void 0 : momentJS.tz)) { throw new Error("The given object doesn't have a 'tz' property. Make sure to import moment-timezone before extending momentjs with moment-timezone-for-local-time."); } momentJS.tz.forLocalTime = forLocalTime; } export { extend, forLocalTime }; //# sourceMappingURL=index.es5.js.map