The problem with date concept!
We, as humans, are good with dates and times. So, why computers are not! Why do they bother us (developers) on this!?
As a matter of fact, the main problem is with different views of different cultures and countries to dates and times. The difficulty comes from the matter that, computers are not racists, they should respect all of our opinions!
Computers wish everything was very simple. They want to represent date and time by something like seconds. Any point in time can be defined as the number of seconds that have elapsed since Thursday, 1 January 1970 00:00:00 (UNIX Time or Epoch Time).
For example my birth date is 475236000 seconds! You can calculate yours here: www.epochconverter.com!
But unfortunately, people don't like this kind of representation (including me!). I don't know about you, but I can not remember such number! So humans prefer to divide it into some meaningful parts: years, months, days. This is what we know as Calendars.
Calendar is a way to divide seconds into meaningful parts: years, months and days.
But historically, different nations and cultures created different calendars. Possibly you have already heard of these calendars:
- Georgian Calendar: I'm sure you know it!
- Solar Calendar: based on perceived seasonal changes synchronized to the apparent motion of the Sun.
So, what is so difficult about having different calendars.
Arranging a meeting for One month Later
Consider we (me and you) are going to arrange a meeting for one month later. What is the meaning of "one month later"? Is it 30 days later or 31 days later?
What is the meaning of one month later', is it 30 days later or 31?
You may say that if we are in the middle of a month with 30 days, then it is 30 days later. So the meaning of one month later varies depending on the time we are in. Lets make it a little more complicated and bring multiple calendars into the game. Consider that me and you are living in different countries with different calendars. In my country current month has 30 days and in your country current month has 31 days. Now, what about setting an arrangement for one month later!? So, not only it depends on the current time, but also it depends to the culture we're using.
So, as the 'one month later' is a vague expression, there will be never a reliable appointment unless we use "days" to specify the appointment time. Here you see that representing duration with month and year is not safe. it must be represented using days or smaller units like hours and minutes.
Here you see that representing duration with month and year is not safe. it must be represented using days or smaller units like hours and minutes.
So, computers have a huge problem with different calendars as they should provide service for all countries with different cultures. As the target market of most applications is local, it is not a big deal usually. But there are some situations which this complexities could not be ignored , like in Aviation Industry. An airline company necessarily works with different airports located in different countries with different calendars (and even worse, with different time zones). So you should deal with this problem and design solutions for the specific business stories. I had a great experience while working in Mahan Airlines as there was lots of challenges with different calendars and different time zones (which is way more harder). There are some great libraries to manage this complexities which I suggest you to utilize in your projects:
- Joda-Time: if you're targeting Java 7 (it is built-in for Java 8)
- Noda Time: by John Skeet for .Net platform
Finally, the story of the astrolabe in the picture. It is one of those first inventions for locating and predicting the positions of the Sun, Moon, planets, and stars which leads to create more precise calendars based on them.
Asturlab is an arabization of this Persian phrase" (sitara yab, meaning "taker of the stars") -Wikipedia