|
|
The Chinese New Year
You are here: irt.org | Articles | JavaScript | Date and Time | The Chinese New Year Published on: Saturday 1st November 1997 By: Martin Webb IntroductionThis article describes how to show the year of the chinese calendar that a date falls in, including the dates and days for the year. More Arrays of DataThe following additional arrays are utilised in this article, using the makeArray() function described in Blind Date:
The Chinese year names have a sixty-year cycle, and are created by pairing a Celestrial Stem with a Terrestrial Branch. The Celestial Stems are specified by Chinese characters that have no English translation; the Terrestrial Branches are named after twelve animals.
The initial year (jia-zi) of the current cycle began on 1984 February 2. The full list of the sexagenary year names is as follows:
The Chinese celebrate New Year's Day sometime between January 10th and February 19th of the Gregorian calendar. The following chinesenewyear[] array holds the dates of the Chinese New Year from 1900 to 1999, in the format M.DD, where M is the number of the month, and DD is the date within the month M:
So for example in 1900 the Chinese New Year fell on 1.31, i.e. the 31st of January. For years outside this range, only a rough estimate of the animal associated with each year is calculated. The Year of the DragonNot unlike a leap year, where you simple divide the year with 4, 100, or 400 to test whether or not a year is a leap year, to calculate the Chinese branch, you must first subtract 3 from the year before dividing by 12 to find out which animal is associated with the year:
So for example, for 1997: To retrieve the Chinese stem, it is necessary to subtract 3 from the year and then divide by 10:
So for 1997: Therefore 1997 was the Chinese year Chou-Ding, or the year of the Ox. However, life is not that simple. As mentioned, the start of the Chinese New Year varies from January 10th to February 19th. People always think that because I was born in 1965 then that means I was born in the year of the Snake. But because I was born on the 4th January, I was actually born in the year of the Dragon. By testing the start of the Chinese New Year, we can account for this. Rather than calculate the beginning of the Chinese New Year, which may even be beyond the capability of JavaScript (although I am currently working on this), we'll use the chinesenewyear[] array described above. To retrieve the details for any particular year from 1900 to 1999 we use the following:
To retrieve the month and day from a floating point number, e.g. 9.99, we use the following:
Then all we need to do is compare the date entered with the start of the Chinese New Year, if its the same or greater then it is a simple matter of retrieving the chinese branch for the year, and if its less than then it requires retrieving the chinese branch for the previous year:
The following Chinese() function does all of this and more. It returns the animal name for the day, month and year passed, and also calculates the values of chineseyearrange the Chinese year range for the date, and chineseyearname the full name of the Chinese year. The chineseyearrange can only be correctly returned for the years 1901 to 1998, as we must have the values for the years before 1901 and after 1998 to correctly calculate the start and end of the relevant years. It also makes use of the FullDate() function described in the previous article Monday's child is full of grace
To retrieve the data the following JavaScript defines two global variables chineseyearrnage and chineseyearname which are populated by the Chinese() function:
Working ExampleWhy not try it out the frame version yourself. Source CodeYou can view the source code of the four components: Feedback on 'The Chinese New Year'
View the profile on Martin Webb and the list of other Articles by Martin Webb. |
-- div -->
|