Public
Edited
Jun 12, 2023
Insert cell
Insert cell
startOfEmployment = "2022-09-01"
Insert cell
startOfLeave = "2023-02-05"
Insert cell
endOfLeave = "2023-02-12"
Insert cell
startOfInterval(startOfEmployment, startOfLeave)
Insert cell
function startOfInterval(startOfEmployment, startOfLeave) {
// Parse the dates
const employmentDate = new Date(startOfEmployment);
const leaveDate = new Date(startOfLeave);

// Get the end of the month one month after employment
employmentDate.setMonth(employmentDate.getMonth() + 2);
employmentDate.setDate(0);

// Get the date six months before leave
leaveDate.setMonth(leaveDate.getMonth() - 6);

if (employmentDate > leaveDate) {
// Get the first day of the next month after employment
employmentDate.setDate(1);
return employmentDate;
} else {
return leaveDate;
}
}
Insert cell
endOfInterval(startOfLeave)
Insert cell
function endOfInterval(startOfLeave) {
// Parse the date
const leaveDate = new Date(startOfLeave);

// Get the end of the month one month before the start of leave
//leaveDate.setMonth(leaveDate.getMonth());
leaveDate.setDate(0);

return leaveDate;
}
Insert cell
function hungarianYearAndMonthName(date) {
// toLocaleString takes a locale string ("hu" for Hungarian) and an object specifying what parts of the date we want
const formattedDate = date.toLocaleString('hu', {year: 'numeric', month: 'long'});

// now we return it in your desired format
return formattedDate;
}

Insert cell
hungarianYearAndMonthName(new Date())
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more