Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org

Related items

JavaScript Y2K Issues

And now...The Weekly Update Script

The 24 Hour World

Today's The Day

Extending "Born of the 4th of July"

Easter

The 3rd Saturday in November

Born on the 4th of July

The Chinese New Year

Monday's child is full of grace

What sign are you?

You are here: irt.org | Articles | JavaScript | Date and Time | What sign are you? [ previous next ]

Published on: Friday 24th October 1997 By: Martin Webb

Introduction

This article calculates the zodiac sign that a date falls in, including the dates and days for the year, along with the birthstone associated with the month.

More Arrays of Data

The following addition arrays are utilised in this article, using the makeArray() function described in Blind Date:

var horroscopes = new makeArray(20,19,21,21,21,21,22,22,22,23,22,21);
var starsigns   = new makeArray('Capricorn','Aquarius','Pisces',
                                'Aries','Taurus','Gemini',
                                'Cancer','Leo','Virgo',
                                'Libra','Scorpio','Sagittarius');
var starsymbols = new makeArray('Goat','Water Bearer','Fishes',
                                'Ram','Bull','Twins',
                                'Crab','Lion','Virgin',
                                'Balance','Scorpion','Archer');

The horroscopes array contains the day of the month that each zodiac star sign starts on, starting with Aquarius.

The starsigns[] array contains the name of the twelve star signs.

The starsymbols[] array contains the twelve constellations:

starsigns[ ]StartFinishstarsymbols[ ]
Capricorn December 21 - January 19 Goat
Aquarius January 20 - February 18 Water Bearer
Pisces February 19 - March 20 Fishes
Aries March 21 - April 20 Ram
Taurus April 21 - May 20 Bull
Gemini May 21 - June 20 Twins
Cancer June 21 - July 21 Crab
Leo July 22 - August 21 Lion
Virgo August 22 - September 21Virgin
Libra September 22 - October 22 Balance
Scorpio October 23 - November 21 Scorpion
SagittariusNovember 22 - December 20 Archer

var birthstones = new makeArray('Garnet','Amethyst','Aquamarine, Bloodstone',
                                'Diamond','Emerald','Pearl, Alexandrite, Moonstone',
                                'Ruby','Peridot, Sardonyx','Sapphire',
                                'Opal, Tourmaline','Topaz','Turquoise, Zircon');
var qualities   = new makeArray('Constancy','Sincerity','Courage',
                                'Innocence','Love, success','Health, longevity',
                                'Contentment','Married happiness','Clear thinking',
                                'Hope','Fidelity','Prosperity');

The birthstones[] array contains the list of birthstones associated with each month.

In 1912, the National Association of Jewelers adopted the standardised list that is widely used today:

monthsofyear[ ]birthstones[ ] qualities[ ]
January Garnet Constancy
February Amethyst Sincerity
March Aquamarine, Bloodstone Courage
April Diamond Innocence
May Emerald Love, success
June Pearl, Alexandrite, MoonstoneHealth, longevity
July Ruby Contentment
August Peridot, Sardonyx Married happiness
SeptemberSapphire Clear thinking
October Opal, Tourmaline Hope
November Topaz Fidelity
December Turquoise, Zircon Prosperity

The third column, Quality, is the quality commonly associated with the birthstone.

You're Aries aren't you?

Given the day of the month that someones born on, you can calculate their star sign by using the horroscopes[] array and the following StarSing() function. It calculates the star sign by checking to see if the day of the month is less than the values for that month in the horroscopes[] array. And, if it is it returns the value for that month, else it returns the value for the next month (after checking for the end of the year).

function StarSign(day,month) {
    if (day < horroscopes[month])
        return month;
    else if (month == 12)
        return 1;
    else
        return month + 1;
}

Which can be used to retrieve the star sign and symbol from the starsigns[] and starsymbol[] arrays:

document.write(starsigns[StarSign(day,month)] +' - '+ starsymbols[StarSign(day,month)]);

The following StarDate() function uses the FullDate() function described in the previous article Monday's child is full of grace to return the date range for the current zodiac star sign.

function StarDate(day,month,year) {
    var beginYear = year;
    var endYear = year;
    var beginMonth = month;
    var endMonth = month;

    if (day < horroscopes[month])
        beginMonth--;
    else 
        endMonth++;
    
    if (beginMonth == 0) {
        beginMonth = 12;
        beginYear--;
    }
    else if (endMonth == 13) {
        endMonth = 1;
        endYear++;
    }

    beginDay = horroscopes[beginMonth];
    endDay = horroscopes[endMonth] - 1;

    return FullDate(beginDay,beginMonth,beginYear) +
           ' - ' +
           FullDate(endDay,endMonth,endYear);
}

For example:

document.write(StarDate(day,month,year));

Diamonds are Forever

The following retrieves the relevant birthstone and quality from the birthstones[] and qualities[] arrays:

document.write('Birthstone ' + birthstones[month] + ' Symbolizes ' + qualities[month]);

Working Example

Why not try out the frame version yourself.

Source Code

You can view the source code of the four components:

Related items

JavaScript Y2K Issues

And now...The Weekly Update Script

The 24 Hour World

Today's The Day

Extending "Born of the 4th of July"

Easter

The 3rd Saturday in November

Born on the 4th of July

The Chinese New Year

Monday's child is full of grace

©2018 Martin Webb