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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more