How to use the moment.tz function in moment

To help you get started, we’ve selected a few moment 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 CSCfi / exam / app / frontend / src / dashboard / student / studentDashboard.service.ts View on Github external
private setOccasion(reservation: Reservation) {
        const machine = reservation.machine;
        const external = reservation.externalReservation;
        let tz;
        if (external) {
            tz = external.roomTz;
        } else if (machine) {
            tz = machine.room.localTimezone;
        }
        // const tz = machine ? machine.room.localTimezone : external.roomTz;
        const start = moment.tz(reservation.startAt, tz);
        const end = moment.tz(reservation.endAt, tz);
        if (start.isDST()) {
            start.add(-1, 'hour');
        }
        if (end.isDST()) {
            end.add(-1, 'hour');
        }
        reservation.occasion = {
            startAt: start.format('HH:mm'),
            endAt: end.format('HH:mm')
        };
    }
github artsy / metaphysics / src / lib / date.ts View on Github external
export function dateTimeRange(
  startAt,
  endAt,
  timezone,
  displayDayOfWeek = false
) {
  const now = moment.tz(moment(), timezone)
  const startMoment = moment.tz(startAt, timezone)
  const endMoment = moment.tz(endAt, timezone)
  const startHourFormat = "h:mma"
  const endHourFormat = "h:mma z"
  let monthFormat = "MMM D"
  const dayFormat = "ddd"

  if (
    startMoment.year() !== endMoment.year() ||
    now.year() !== startMoment.year()
  ) {
    // Adds years if the dates are not the same year
    monthFormat = monthFormat.concat(", YYYY")
  }

  if (datesAreSameDay(startAt, endAt, timezone)) {
    return displayDayOfWeek
      ? `${startMoment.format(dayFormat)}, ${startMoment.format(
github artsy / metaphysics / src / lib / date.ts View on Github external
export function singleDateTime(date, timezone) {
  const now = moment.tz(moment(), timezone)
  const thisMoment = moment.tz(date, timezone)
  if (now.year() !== thisMoment.year()) {
    return `${thisMoment.format("MMM D, YYYY")} at ${thisMoment.format(
      "h:mma z"
    )}`
  } else {
    return `${thisMoment.format("MMM D")} at ${thisMoment.format("h:mma z")}`
  }
}
github streamr-dev / streamr-platform / app / src / userpages / components / StreamPage / List / index.jsx View on Github external
className={styles.signedTick}
                                                                    />}
                                                                
                                                                <span>
                                                                    {stream.description}
                                                                </span>
                                                                <span>
                                                                    {stream.lastUpdated &amp;&amp; (
                                                                        moment.min(moment.tz(stream.lastUpdated, timezone), nowTime).fromNow()
                                                                    )}
                                                                </span>
                                                            
                                                            <div>
                                                                <span>
                                                                    {stream.lastUpdated &amp;&amp; (
                                                                        moment.min(moment.tz(stream.lastUpdated, timezone), nowTime).fromNow()
                                                                    )}
                                                                </span>
                                                                
                                                            </div>
                                                        
                                                    
                                                
                                            ))}
github artsy / metaphysics / src / lib / date.ts View on Github external
export function timeRange(startAt, endAt, timezone) {
  const startMoment = moment.tz(startAt, timezone)
  const endMoment = moment.tz(endAt, timezone)
  let startHour
  let endHour = endMoment.format("h:mma z")
  if (
    (startMoment.hours() &lt;= 12 &amp;&amp; endMoment.hours() &lt;= 12) ||
    (startMoment.hours() &gt;= 12 &amp;&amp; endMoment.hours() &gt;= 12)
  ) {
    startHour = startMoment.format("h:mm")
  } else {
    startHour = startMoment.format("h:mma")
  }

  return `${startHour}${endHour}`
}
github Aceheliflyer / AceBot / src / commands / information / inviteinfo.js View on Github external
this.client.fetchInvite(args.invite).then(invite => {
      var inviter = invite.inviter
      var guild = invite.guild

      message.embed({
        author: { name: this.client.user.tag, icon_url: this.client.user.displayAvatarURL() },
        footer: { text: message.author.tag, icon_url: message.author.displayAvatarURL() },
        timestamp: new Date(),
        title: guild.name,
        description: `Since ${moment(guild.createdAt).format('llll')} ${moment.tz(moment.tz.guess()).format('z')}`,
        thumbnail: { url: guild.iconURL() !== null ? guild.iconURL() : 'http://cdn.discordapp.com/embed/avatars/0.png' },
        fields: [
          {
            'name': 'Inviter',
            'value': invite.inviter === undefined ? 'N/A' : stripIndents`
              **Name:** ${escapeMarkdown(`${inviter.username}#${inviter.discriminator}`)}
              **ID:** ${inviter.id}
              **Status:** ${inviter.presence.status}
            `,
            'inline': true
          },
          {
            'name': 'Members',
            'value': invite.memberCount,
            'inline': true
          }
github artsy / metaphysics / src / lib / date.ts View on Github external
export function formattedOpeningHours(startAt, endAt, timezone) {
  const thisMoment = moment()
  const startMoment = moment.tz(startAt, timezone)
  const endMoment = moment.tz(endAt, timezone)
  if (thisMoment.isBefore(startMoment)) {
    return `Opens ${singleDateTime(startAt, timezone)}`
  } else if (thisMoment.isBefore(endMoment)) {
    return `Closes ${singleDateTime(endAt, timezone)}`
  } else {
    return "Closed"
  }
}
github WordPress / gutenberg / packages / date / src / index.js View on Github external
export function getDate( dateString ) {
	if ( ! dateString ) {
		return momentLib.tz( WP_ZONE ).toDate();
	}

	return momentLib.tz( dateString, WP_ZONE ).toDate();
}
github sharedstreets / sharedstreets-road-closure-ui / src / models / RoadClosureWazeIncidentsItem.ts View on Github external
bothDirections: boolean,
        schedule?: IRoadClosureSchedule,
        week?: string
    ) {
        this.creationtime = moment().format();
        
        if (schedule && week) {
            this.starttime = form.startTime ? this.setStartTimeByWeek(form.startTime, form.timezone, parseInt(week, 10)) : '';
            this.endtime = form.endTime ? this.setEndTimeByWeek(form.endTime, form.timezone, parseInt(week, 10)) : '';
            if (!isEmpty(this.setSchedule(schedule))) {
                this.schedule = this.setSchedule(schedule);
            }
        } else {
            if (form.timezone) {
                this.starttime = moment.tz(form.startTime, form.timezone).format();
                this.endtime = moment.tz(form.endTime, form.timezone).format();
            } else {
                this.starttime = moment(form.startTime).format();
                this.endtime = moment(form.endTime).format();
            }
        }
        this.type = form.type;
        this.subtype = form.subtype;
        this.description = form.description;
        this.mode = form.mode;
        this.fromIntersectionClosed = !!matchedStreetSegment.properties.fromIntersectionClosed;
        this.toIntersectionClosed = !!matchedStreetSegment.properties.toIntersectionClosed;

        this.location.direction = bothDirections ? "BOTH_DIRECTIONS" : "ONE_DIRECTION";
        this.location.incidentId = uuid();
        this.location.referenceId = matchedStreetSegment.properties.referenceId;
        this.location.fromStreetnames = matchedStreetSegment.properties.fromStreetnames;
github CartoDB / cartodb / lib / assets / javascripts / cartodb3 / editor / widgets / widgets-form / schema / widgets-form-time-series-schema-model.js View on Github external
.reduce(function (memo, tz) {
        var name = tz.name;

        memo.push({
          label: tz.label,
          name: name,
          offset: moment.tz(name).utcOffset()
        });

        return memo;
      }, [])
      .sortBy('offset')