How to use the moment-timezone.utc 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 tidepool-org / tideline / js / data / util / format.js View on Github external
timeChangeInfo: function(from, to) {
    if (!to) { // guard statement
      throw new Error('You have not provided a `to` datetime string');
    }

    // the "from" and "to" fields of a time change are always timezone-naive
    // timestamps by definition (b/c they are device-relative time)
    // but some (versions) of (some) browsers like to coerce timestamps without TZ info into local time
    // and we need to prevent that, so we use moment.utc and then use the UTC
    // variant of all JS Date methods to ensure consistency across browsers
    var fromDate = from ? moment.utc(from).toDate() : undefined;
    var toDate = moment.utc(to).toDate();
    var type = 'Time Change';

    var format = 'h:mm a';
    if (fromDate && toDate) {
      if (fromDate.getUTCFullYear() !== toDate.getUTCFullYear()) {
        format = 'MMM D, YYYY h:mm a';
      } else if (
        fromDate.getUTCMonth() !== toDate.getUTCMonth() ||
        fromDate.getUTCDay() !== toDate.getUTCDay()
      ) {
        format = 'MMM D, h:mm a';
      }

      if (Math.abs(toDate - fromDate) <= (8*(60*1000))) { // Clock Drift Adjustment if less than 8 minutes
        type = 'Clock Drift Adjustment';
github TEAMMATES / teammates / src / web / app / pages-session / session-submission-page / session-submission-page.component.ts View on Github external
const submissionEndTime: any = moment(feedbackSession.submissionEndTimestamp);
          this.formattedSessionClosingTime = submissionEndTime
              .tz(feedbackSession.timeZone).format(TIME_FORMAT);

          this.feedbackSessionSubmissionStatus = feedbackSession.submissionStatus;

          // don't show alert modal in moderation
          if (!this.moderatedPerson) {
            switch (feedbackSession.submissionStatus) {
              case FeedbackSessionSubmissionStatus.VISIBLE_NOT_OPEN:
                this.isSubmissionFormsDisabled = true;
                this.modalService.open(FeedbackSessionNotOpenModalComponent);
                break;
              case FeedbackSessionSubmissionStatus.OPEN:
                // closing in 15 minutes
                if (moment.utc().add(15, 'minutes').isAfter(submissionEndTime)) {
                  this.modalService.open(FeedbackSessionClosingSoonModalComponent);
                }
                break;
              case FeedbackSessionSubmissionStatus.CLOSED:
                this.isSubmissionFormsDisabled = true;
                this.modalService.open(FeedbackSessionClosedModalComponent);
                break;
              case FeedbackSessionSubmissionStatus.GRACE_PERIOD:
              default:
            }
          }

          this.loadFeedbackQuestions();
        }, (resp: ErrorMessageOutput) => {
          if (resp.status === 404) {
github bgerm / scheduler3000 / server / models / event.js View on Github external
const sameDay = (utc, timezone) => {
  const { years, months, date } = moment.utc(utc).toObject();
  return moment.tz([years, months, date], timezone);
};
github epam / cloud-pipeline / client / src / utils / displayDuration.js View on Github external
export default (start, end = undefined) => {
  if (!start && !end) {
    return null;
  }
  const diff = moment
    .utc(end ? moment.utc(end) : moment.utc())
    .diff(moment.utc(start), 'seconds', false);
  const MINUTE = 60;
  const HOUR = 60 * MINUTE;
  const DAY = 24 * HOUR;
  const days = Math.floor(diff / DAY);
  const hours = Math.floor((diff - days * DAY) / HOUR);
  const minutes = Math.floor((diff - days * DAY - hours * HOUR) / MINUTE);
  const seconds = diff - days * DAY - hours * HOUR - minutes * MINUTE;
  const plural = (count, word) => `${count} ${word}${count === 1 ? '' : 's'}`;
  if (days > 0) {
    return plural(days, 'day');
  }
  if (hours > 0) {
    return plural(hours, 'hour');
  }
github epam / cloud-pipeline / client / src / components / main / home / HomePage.js View on Github external
componentWillUnmount () {
    clearInterval(this.updateInterval);
    localStorage.setItem('LAST_VISITED', moment.utc().format('YYYY-MM-DD HH:mm:ss'));
    window.removeEventListener('resize', this.onWindowResized);
  }
}
github bgerm / scheduler3000 / server / controllers / api / events.js View on Github external
const sameDayUTC = (utc, timezone) => {
  const { years, months, date } = moment.utc(utc).tz(timezone).toObject();
  return moment.utc([years, months, date]);
};
github tidepool-org / viz / src / utils / print / data.js View on Github external
.tz(timezone)
      .subtract(1, 'day')
      .toDate();
    dateBoundaries.push(
      startOfDate.toISOString()
    );
    last = startOfDate;
  }
  dateBoundaries.reverse();

  const selected = { dataByDate: {}, dateRange: [], timezone };

  for (let i = 0; i < numDays; ++i) {
    const thisDateStart = dateBoundaries[i];
    const thisDateEnd = dateBoundaries[i + 1];
    const date = moment.utc(Date.parse(thisDateStart))
      .tz(timezone)
      .format('YYYY-MM-DD');
    selected.dataByDate[date] = {
      bounds: [Date.parse(thisDateStart), Date.parse(thisDateEnd)],
      date,
      data: _.mapValues(groupedData, (dataForType) => {
        if (_.isEmpty(dataForType)) {
          return [];
        }
        const filterFn = _.includes(['basal', 'bolus'], dataForType[0].type) ?
          filterWithDurationFnMaker(thisDateStart, thisDateEnd) :
          filterPointInTimeFnMaker(thisDateStart, thisDateEnd);
        return _.sortBy(_.map(
          _.filter(dataForType, filterFn),
          (d) => {
            const reshaped = stripDatum(d);
github cloudfoundry-incubator / service-fabrik-broker / api-controllers / ServiceFabrikAdminController.js View on Github external
getScheduledBackupInstances(req, res) {
    if (req.query.start_time && !moment(req.query.start_time, CONST.REPORT_BACKUP.INPUT_DATE_FORMAT, true).isValid()) {
      throw new BadRequest(`Invalid start date, required format ${CONST.REPORT_BACKUP.INPUT_DATE_FORMAT}`);
    }
    if (req.query.end_time && !moment(req.query.end_time, CONST.REPORT_BACKUP.INPUT_DATE_FORMAT, true).isValid()) {
      throw new BadRequest(`Invalid end date, required format ${CONST.REPORT_BACKUP.INPUT_DATE_FORMAT}`);
    }
    const start_time = req.query.start_time ? moment.utc(req.query.start_time).toDate() : undefined;
    const end_time = req.query.end_time ? moment.utc(req.query.end_time).endOf('day').toDate() : undefined;
    return BackupReportManager
      .getInstancesWithBackupScheduled(start_time, end_time)
      .then(body => res
        .status(200)
        .send(body));
  }
github esnet / pond / packages / pond / src / util.ts View on Github external
if (isIndexString(indexString)) {
                return indexString;
            } else if (!_.isNaN(parseInt(parts[0], 10)) && !_.isNaN(parseInt(parts[1], 10))) {
                const parsedYear = parseInt(parts[0], 10);
                const parsedMonth = parseInt(parts[1], 10);
                t = moment.utc([parsedYear, parsedMonth - 1]);
                if (format) {
                    return t.format(format);
                } else {
                    return t.format("MMMM");
                }
            }
            break;
        case 1:
            const year = parts[0];
            t = moment.utc([year]);
            if (format) {
                return t.format(format);
            } else {
                return t.format("YYYY");
            }
    }
    return indexString;
}