Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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')
};
}
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(
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")}`
}
}
className={styles.signedTick}
/>}
<span>
{stream.description}
</span>
<span>
{stream.lastUpdated && (
moment.min(moment.tz(stream.lastUpdated, timezone), nowTime).fromNow()
)}
</span>
<div>
<span>
{stream.lastUpdated && (
moment.min(moment.tz(stream.lastUpdated, timezone), nowTime).fromNow()
)}
</span>
</div>
))}
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() <= 12 && endMoment.hours() <= 12) ||
(startMoment.hours() >= 12 && endMoment.hours() >= 12)
) {
startHour = startMoment.format("h:mm")
} else {
startHour = startMoment.format("h:mma")
}
return `${startHour} – ${endHour}`
}
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
}
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"
}
}
export function getDate( dateString ) {
if ( ! dateString ) {
return momentLib.tz( WP_ZONE ).toDate();
}
return momentLib.tz( dateString, WP_ZONE ).toDate();
}
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;
.reduce(function (memo, tz) {
var name = tz.name;
memo.push({
label: tz.label,
name: name,
offset: moment.tz(name).utcOffset()
});
return memo;
}, [])
.sortBy('offset')