How to use the moment-timezone.duration function in moment-timezone

To help you get started, we’ve selected a few moment-timezone examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kevinsuh / toki / src / bot / controllers / work_sessions / endWorkSession.js View on Github external
console.log("all work sessions:");
							console.log(workSessions);

							var endTime = moment();
							// IF you chose a new task not on your list to have completed
							if (differentCompletedTask) {

								var minutes; // calculate time worked on that task
								if (workSessions.length > 0) {

									// use this to get how long the
									// custom added task took
									var startSession = workSessions[0];
									var startTime    = moment(startSession.startTime);
									minutes          = moment.duration(endTime.diff(startTime)).asMinutes();

								} else {
									// this should never happen.
									minutes = 30; // but if it does... default minutes duration
								}

								// create new task that the user just got done
								user.getDailyTasks({
									where: [ `"DailyTask"."type" = ?`, "live" ]
								})
								.then((dailyTasks) => {
									const priority = dailyTasks.length+1;
									const text     = differentCompletedTask;
									// record the different completed task
									models.Task.create({
										text,
github juttle / juttle / lib / runtime / types / juttle-moment.js View on Github external
normalize() {
        // XXX momentjs behaves badly with durations having
        // floating-point days, so be sure we always give integer days
        // until we get a straight answer from the momentjs crew. This
        // is a narrow fix for a narrow bug, non-day units are not a problem.
        if (!this.duration) {
            return ;
        }
        var floatdays = this.duration.days();
        var days = (floatdays >= 0)? Math.floor(floatdays) : Math.ceil(floatdays);
        if (floatdays === days) {
            return ;
        }
        this.duration.subtract(moment.duration({days: floatdays - days}));
        this.duration.add(moment.duration({milliseconds:(floatdays - days) * 86400 * 1000}));
    }
github kevinsuh / toki / src / bot / controllers / sessions / startSessionFunctions.js View on Github external
callback: (response, convo) => {

				let now                            = moment().tz(tz);
				let { intentObject: { entities } } = response;
				// for time to tasks, these wit intents are the only ones that makes sense
				let customTimeObject = witTimeResponseToTimeZoneObject(response, tz);
				if (customTimeObject) {
					let minutes = Math.round(moment.duration(customTimeObject.diff(now)).asMinutes());
					convo.sessionStart.minutes = minutes;
					finalizeSessionTimeAndContent(convo);
					convo.next();
				} else {
					// invalid
					convo.say("I'm sorry, I didn't catch that :dog:");
					let question = `How much more time did you want to add to \`${content}\` today?`;
					convo.repeat();
				}

				convo.next();

			}
		}
github sebbo2002 / ical-generator / test / test_alarm.js View on Github external
it('setter should work with moment.duration', function () {
            const a = new ICalAlarm(null, new ICalEvent(null, new ICalCalendar()));
            a.triggerBefore(moment.duration(2, 'minutes'));
            assert.strictEqual(a._data.trigger, -120);
        });
github linode / manager / src / utilities / formatDate.ts View on Github external
  week: () => moment.duration(1, 'weeks'),
  month: () => moment.duration(1, 'months'),
github Foundry376 / Mailspring / app / src / services / battery-status-manager.es6 View on Github external
_onChargingChange = () => {
    const changeTime = Date.now();
    Actions.recordUserEvent('Battery State Changed', {
      oldState: this.isBatteryCharging() ? 'battery' : 'ac',
      oldStateDuration: Math.min(
        changeTime - this._lastChangeTime,
        moment.duration(12, 'hours').asMilliseconds()
      ),
    });
    this._lastChangeTime = changeTime;
    this._callbacks.forEach(cb => cb());
  };
github juttle / juttle / lib / runtime / types / juttle-moment.js View on Github external
clone() {
        return new JuttleMoment({
            duration: this.duration && moment.duration(this.duration),
            moment: this.moment && this.moment.clone()
        });
    }
github kevinsuh / toki / src / bot / controllers / modules / startWorkSessionFunctions.js View on Github external
callback: function(response, convo) {

					let { intentObject: { entities } } = response;

					let now              = moment().tz(tz);
					let customTimeObject = witTimeResponseToTimeZoneObject(response, tz);

					if (customTimeObject) {
						let minutes          = Math.round(moment.duration(customTimeObject.diff(now)).asMinutes());

						convo.sessionStart.calculatedTimeObject = customTimeObject;
						convo.sessionStart.minutes              = minutes;
						convo.sessionStart.confirmStart         = true;

						convo.next();

					} else {
						convo.say("I didn't quite get that :thinking_face:");
						convo.repeat();
						convo.next();
					}

				}
			}
github webkom / lego-webapp / app / routes / events / components / JoinEventFormCountdownProvider.js View on Github external
export function getTimeUntil(
  time: Dateish,
  currentTime?: Dateish = moment()
): moment$MomentDuration {
  return moment.duration(getTimeDifference(time, currentTime), 'milliseconds');
}