According to many other excellent postings to the topic of creating and use of a master calendar here one which creates a 4-5-4 calendar. In short a 4-5-4 calendar focused on complete weeks and each quarter contains 4 + 5 + 4 weeks = 91 days * 4 quarter = 364 days and each 6 years is a leap year with an extra week (over longer periods it's of course more complicated).
The reasons for using are statistical advantages mainly within the financial planning.
This calendar based on: Wochenkalender.
I think some things could be solved more elegant and more generic (but for two aspects it was easier to include a simple mapping-table) and there could be more functions and data-fields like monthend(), workingdays() or to implement a list of holidays. But the aim wasn't to include all imaginable functionalities else to give you some hints to solve such and similar cases.
Update: Here are other ways to create Non-Gregorian calendars.
You are invited to suggest improvements. Have fun!