Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const end = DateTime.fromISO('2017-03-13');
const start = DateTime.fromISO('2017-02-13');
const diffInMonths = end.diff(start, 'months');
diffInMonths.toObject().months; // $ExpectType number | undefined
const diff = end.diff(start);
diff.toObject().milliseconds; // $ExpectType number | undefined
end.diff(start, ['months', 'days']).months; // $ExpectType number
end.diffNow(['months', 'days']); // $ExpectType Duration
dur.as('days'); // $ExpectType number
dur.shiftTo('days').toObject().days; // $ExpectType number | undefined
dur.shiftTo('week', 'hours').toObject().weeks; // $ExpectType number | undefined
DateTime.local().plus(dur.shiftTo('milliseconds')).year; // $ExpectType number
Duration.fromISO('PY23', { conversionAccuracy: 'longterm' }); // $ExpectType Duration
end.diff(start, 'hours', { conversionAccuracy: 'longterm' }); // $ExpectType Duration
end.diff(start, ['months', 'days', 'hours']); // $ExpectType Duration
dur.reconfigure({ conversionAccuracy: 'longterm' }); // $ExpectType Duration
start.until(end); // $ExpectType Interval
i.toDuration(['years', 'months', 'days']); // $ExpectType Duration
/* Sample Zone Implementation */
class SampleZone extends Zone {
readonly isValid = false;
readonly name = 'Sample';
readonly type = 'Example';
readonly universal = true;
});
var date: DateTime = DateTime.invalid("test");
// $ExpectError
DateTime.invalid();
// Flow 0.40 - 0.45 allows these but they're incorrect...bug!
// DateTime.max();
// DateTime.min();
var date = DateTime.max(DateTime.local(), DateTime.utc(), DateTime.utc());
var date = DateTime.min(DateTime.local(), DateTime.utc(), DateTime.utc());
// $ExpectError
var date = DateTime.max(DateTime.local(), null, DateTime.utc());
// $ExpectError
var date = DateTime.min(DateTime.local(), null, DateTime.utc());
(date.day: number);
(date.daysInMonth: number);
(date.daysInYear: number);
(date.hour: number);
(date.invalidReason: ?string);
(date.isInDST: boolean);
(date.isInLeapYear: boolean);
(date.isOffsetFixed: boolean);
(date.isValid: boolean);
(date.locale: string);
(date.millisecond: number);
(date.minute: number);
(date.month: number);
(date.monthLong: string);
(date.monthShort: string);
});
var date: DateTime = DateTime.invalid("test");
// $ExpectError
DateTime.invalid();
// Flow 0.40 - 0.45 allows these but they're incorrect...bug!
// DateTime.max();
// DateTime.min();
var date = DateTime.max(DateTime.local(), DateTime.utc(), DateTime.utc());
var date = DateTime.min(DateTime.local(), DateTime.utc(), DateTime.utc());
// $ExpectError
var date = DateTime.max(DateTime.local(), null, DateTime.utc());
// $ExpectError
var date = DateTime.min(DateTime.local(), null, DateTime.utc());
(date.day: number);
(date.daysInMonth: number);
(date.daysInYear: number);
(date.hour: number);
(date.invalidReason: ?string);
(date.isInDST: boolean);
(date.isInLeapYear: boolean);
(date.isOffsetFixed: boolean);
(date.isValid: boolean);
(date.locale: string);
(date.millisecond: number);
(date.minute: number);
(date.month: number);
(date.monthLong: string);
(date.monthShort: string);
const memberships = this.route.snapshot.data.memberships;
this.currentYear = DateTime.local().year;
// memberships are sorted from latest to oldest, so the current one can only be the first one
if (memberships.length > 0 && memberships[0].year === this.currentYear) {
this.currentMembership = memberships[0];
this.oldMemberships = memberships.slice(1);
} else {
this.oldMemberships = memberships;
}
this.person = this.currentPersonService.snapshot;
this.membershipForm = this.fb.group({
paymentMode: [null, Validators.required],
paymentDate: [DateTime.local().toISODate(), [
Validators.required,
min(DateTime.local(this.currentYear, 1, 1).toISODate()),
pastDate
]],
cardNumber: [null, Validators.required]
});
}
function saveWallet() {
const walletPath = getWalletPath() + userInfo.login + ".awd";
if (fs.existsSync(walletPath)) {
const backupDir = getWalletPath() + "backups";
if (!fs.existsSync(backupDir)) {
fs.mkdirSync(backupDir);
}
const timestamp = DateTime.local().toFormat("yyyyLLddHHmmss");
const backupPath = backupDir + "/" + userInfo.login + "-" + timestamp + ".awd";
//fs.copyFileSync(walletPath, backupPath);
// piece of shit node.js ecosystem, why the fuck do we have to deal with fs-extra crap here?
fs.copySync(walletPath, backupPath);
pruneBackups(backupDir, userInfo.login);
}
exportWallet(walletPath, true);
userInfo.dbChanged = false;
}
function updateDatesInActivity(activity) {
const start = (activity.state.startUnix && !isNaN(activity.state.startUnix)) ? DateTime.fromMillis(activity.state.startUnix * 1000) : DateTime.local();
activity.state.startDate = start.set({millisecond: 0, second: 0}).setZone('Europe/Berlin').toJSDate();
const end = (activity.state.endUnix && !isNaN(activity.state.endUnix)) ? DateTime.fromMillis(activity.state.endUnix * 1000) : DateTime.local();
activity.state.endDate = end.set({millisecond: 0, second: 0}).setZone('Europe/Berlin').toJSDate();
}
changeType(type) {
const defaultValue = (this.isDelayType(type) || this.isCycleType(type))
? defaultDurationValue
: DateTime
.local()
.toUTC()
.toISO();
this.emitChange(type, defaultValue);
},
isDelayType(type) {
static forDuration(duration, parent) {
return this.forDateTime(DateTime.local().plus(duration), parent);
}
});
month = month.plus({months: 1});
}
return {
header: {
delta: {count: 1, unit: "year"},
title: {nextPane: "year", span: 2, value: refTime.value.toFormat("yyyy")},
},
rows: chunkArray(months, 4),
};
}
case "year": {
let year = DateTime.local(Math.floor(refTime.value.year / 10) * 10 - 1);
const start = year;
const end = year.plus({years: 11}).endOf("year");
const years: Array = [];
while (year < end) {
years.push({
current: props.value && year.hasSame(refTime.value, "year"),
disabled: minTime.value !== null && year < minTime.value.startOf("year"),
future: years.length === 11,
past: years.length === 0,
time: year,
value: year.toFormat("yyyy"),
});
year = year.plus({years: 1});
private _computeEndDate(expireIn: Expire) {
const now = DateTime.local();
switch (expireIn) {
case Expire.month1:
return now.plus({months: 1}).toJSDate();
case Expire.year1:
return now.plus({years: 1}).toJSDate();
case Expire.year2:
return now.plus({years: 2}).toJSDate();
default:
return new Date(2299, 12, 31);
}
}
}