Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
So I want to create a much bigger program where I use a calendar control that is created based on a made up calendar. The setup of the days and months are different from the ones that are used on earth now or in the past. What I need is to find a way to build the control based on the chosen month, week, year setup.

I guess I am asking this wrong. How do I calculate a month view for a calendar where the setup of the week length, month length, and year length, can be changed. \

* EDIT2:
I am looking for the math portion of the problem. I can figure out how to do the view portion if I can figure out how to figure out on what day each date falls programicly. If each year has 16 months, with weeks 8 days long, and months ranging from 23 to 34 days long how do I find out what day 9/4/129 (d/m/y) is on.

END EDIT2 *

* EDIT:
I want the user to be able to choose:

  • how many months are in a year
  • how many days are in each month
  • how many days are in a week

END EDIT *

I am using C++ with gcc 5.2.0 on Windows 10 using MSys2. I would like it to function for both 32 and 64 bits ( with 64 bit being able to go farther into the future and past ).

Also if possible be able to add leap year(s) as an option.

Thanks in advanced.
Posted
Updated 19-Dec-15 7:58am
v3
Comments
Dave Kreskowiak 19-Dec-15 12:38pm    
Uhhh.....what? You say you're making up your own calendar but you have no idea ow to program the math for your own calendar. This doesn't make sense. If you're making your own calendar you would also have to come up with the rules for calculating these things and only YOU would be able to write this code based on your own rules.

Are you making up your own calendar or are you making a calendar control to using the Gregorian calendar?
Nicholas Hinkley 19-Dec-15 12:43pm    
What I want to do is create a control that the user can choose how many month are in a year, how many days each month has, how many days are in a week, etc. So that the control can calculate the month view of that date from the makeup of the year.
Andreas Gieriet 19-Dec-15 13:19pm    
To start with, forget about the implementation (the "control*). First you have to have a precise definition of your calendar and what the parameters are.
E.g. each month equally long? What is the leap-year rule? I.e. by what parameters you steer the function of your calendar?
Only if this is given, you can think about how to partition into a "model" of the calendar (the storage and machinery to produce dates) and the "view" of the calendar (how to present and provide edit function to the user). The glue logic between the model and the view will then be the "controller", assuming a MVC (Model-View-Controller) approach.
Cheers
Andi
Nicholas Hinkley 19-Dec-15 13:56pm    
Thank you. I am looking for the math portion of the problem. I can figure out how to do the view portion if I can figure out how to figure out on what day each date falls programicly. If each year has 16 months, with weeks 8 days long, and months ranging from 23 to 34 days long how do I find out what day 9/4/129 (d/m/y) is on.
Andreas Gieriet 20-Dec-15 3:54am    
To start with, don't do any "math", just count from the beginning. Your calendar specification is too imprecise to produce a generally valid formula from that. See also my solution below. The leap days are needed when the calculated year length is "sufficiently" out-of-sync compared with the actual "stellar" year length. You assume here a "stellar" calendar as it looks like. "Lunar" calendars have a different concept of cycles. Or do you assume a year on earth as the base for your calendar?
You see, your specification on what you want to achieve is too imprecise to make reasonable statements on it...
Cheers
Andi

1 solution

You need a start date of the calendar, a first weekday of the calendar, a strategy how to calculate the leap days (in general, leap days do not necessarily need to be at the end of a month and there may be more than one leap day (IIRC, some ancient calendars even had leap months)).
E.g. the Gregorian calendar started on Friday October 15, 1582.
In general, there is no closed math formula for such a generic calendar.
You simply start counting year lengths (including the needed leap days) from the beginning of the calendar and determine the weekday of the first day of that particular year. Then you count up for that year through the months and the leap days to the desired date while keeping track of the weekday.
Cheers
Andi
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900