?

Log in

No account? Create an account
leap year - brad's life — LiveJournal [entries|archive|friends|userinfo]
Brad Fitzpatrick

[ website | bradfitz.com ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

leap year [Feb. 29th, 2004|04:32 pm]
Brad Fitzpatrick
[Tags|, ]

Copying eli and his hardcore test [meme]:
You are not a Hardcore LiveJournal user unless this is the second time you've been able to post on February 29th :-)

First time:
http://www.livejournal.com/users/brad/2000/02/29/
Second time:
Now. :P
Do people with birthdays on Feb. 29 celebrate them on Feb. 28 or Mar. 1 on normal years?

Do you know how to calculate whether it's a leap year or not? It's not just ever 4 years... It's ever 4 years, except every 100 years, except every 400 years. (which is why 2000 was a leap year). Here's the LJ code for it:

sub days_in_month
{   
    my ($month, $year) = @_;
    if ($month == 2)
    {               
        return 29 unless $year;  # assume largest
        if ($year % 4 == 0)
        {
          # years divisible by 400 are leap years
          return 29 if $year % 400 == 0;
    
          # if they're divisible by 100, they aren't.
          return 28 if $year % 100 == 0;

          # otherwise, if divisible by 4, they are.
          return 29;
        }
    }
    return ((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)[$month-1]);
}
LinkReply

Comments:
[User Picture]From: nolegs
2004-02-29 04:45 pm (UTC)
My sixth grade teacher's mother was born on the 29th. He said she would only celebrate her birthday every four years and told everybody she was twenty. She also made the world's greatest fried chicken according to him.
(Reply) (Thread)
[User Picture]From: ydna
2004-02-29 04:47 pm (UTC)
March 1st is what I hear most often. Maybe it's delayed gratification or for people trying to put off getting older a little longer.
(Reply) (Thread)
[User Picture]From: brad
2004-02-29 04:56 pm (UTC)
Well, Dina told me she always hears Feb 28... so maybe it varies with age.
(Reply) (Parent) (Thread)
[User Picture]From: penguinfairy
2004-02-29 04:54 pm (UTC)

hehe

At first, I thought you meant the 2nd time to post on this leap day. Then, I had to keep rereading it, until I realized you meant two separate leap days.

Fevers are mean.
(Reply) (Thread)
[User Picture]From: jwz
2004-02-29 05:20 pm (UTC)
Mine's shorter:

    # Whether the given 4-digit year is a leap year.
    #

    sub leap_year_p {
    my ($year) = @_;
    return ((($year % 4 == 0) && # divisible by 4
    (($year % 100) || # ...unless divisble by 100
    ($year % 400 == 0))) # ...and not divisible by 400
    ? 1 : 0);
    }

    # Returns the number of days in the given month, considering leap years.
    #

    my @days_per_month = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    sub days_per_month {
    my ($month, $year) = @_;
    my $days = $days_per_month[$month-1];
    $days++ if ($month == 2 && leap_year_p($year)); # feb leapday
    return $days;
    }

And this calculation is kinda crazy too:

    # Given a date, returns the day of the week on which it falls (0-6, sun-sat)
    #

    sub dotw {
    my ($dotm, $month, $year) = @_;

    # From the sci.math FAQ:
    #
    # The following formula, which is for the Gregorian calendar only, may be
    # more convenient for computer programming. Note that in some programming
    # languages the remainder operation can yield a negative result if given
    # a negative operand, so "mod 7" may not translate to a simple remainder.
    #
    # W == (k + [2.6m - 0.2] - 2C + Y + [Y/4] + [C/4]) mod 7
    # where [] denotes the integer floor function (round down),
    # k is day (1 to 31)
    # m is month (1 = March, ..., 10 = December, 11 = Jan, 12 = Feb)
    # Treat Jan & Feb as months of the preceding year
    # C is century (1987 has C = 19)
    # Y is year (1987 has Y = 87 except Y = 86 for Jan & Feb)
    # W is week day (0 = Sunday, ..., 6 = Saturday)
    #
    # Here the century & 400 year corrections are built into the formula.
    # The [2.6m-0.2] term relates to the repetitive pattern that the 30-day
    # months show when March is taken as the first month.


    my $k = $dotm;
    my $m = 1 + (($month + 9) % 12); # (1-12) => (11, 12, 1-10)
    my $y = $year - ($m >= 11 ? 1 : 0); # subtract a year for jan/feb
    my $C = int ($y/100);
    my $Y = int ($y%100);
    my $W = (($k +
    int ((2.6 * $m) - 0.2)
    - (2 * $C)
    + $Y
    + int ($Y / 4)
    + int ($C / 4)
    + 7)
    % 7);
    return $W;
    }
(Reply) (Thread)
[User Picture]From: funjon
2004-02-29 05:21 pm (UTC)

from one of the apps i wrote

sub numdays
{
my ($month,$year) = @_;

$month++; # localtime is weird and uses months 0..11, which makes -no- sense to me.

if ($month==2)
{
my $leapyear=($year%4==0?1:0); # A leap year every 4 years
if ($year%100==0 && $year%400!=0) { $leapyear=0; } # Except if year is 100x and not 400x
return (28+$leapyear);
}
if ($month==1 || $month==3 || $month==5 || $month==7 || $month==8 || $month==10 || $month==12)
{
return 31;
}
if ($month==4 || $month==6 || $month==9 || $month==11)
{
return 30;
}
}
(Reply) (Thread)
[User Picture]From: denshi
2004-02-29 05:27 pm (UTC)
We had a leap-year birthday party last night. Come dressed as (your age / 4), pig tails & vodka, pinantas & whiskey, play-doh hazing, birthday cake, the requisite live music.

I love how calendar wonkiness provides reasons to party.
(Reply) (Thread)
[User Picture]From: mart
2004-02-29 06:00 pm (UTC)

I was a few months too late… (May 2000, according to my userinfo page.)

(Reply) (Thread)
[User Picture]From: youngoat
2004-02-29 06:12 pm (UTC)
Did you know there are leap seconds too?

They aren't prescheduled like leap years... They're just inserted as needed... Looks like there have been 22 since 1972...

*shrug* fjarlq pointed them out to me recently and I thought it was pretty interesting. =]
(Reply) (Thread)
[User Picture]From: krellis
2004-02-29 09:35 pm (UTC)
And a certain model of Motorola GPS receiver had a problem late last year because their "time since last leap second" counter overflowed, since we haven't had any leap seconds in so long. See this thread and this page for more information.
(Reply) (Parent) (Thread)
[User Picture]From: holyloki
2004-02-29 06:41 pm (UTC)

mannn

I missed it by exactly 3 weeks... D :
heh.
(Reply) (Thread)
[User Picture]From: patrick
2004-02-29 07:14 pm (UTC)

Re: mannn

I missed it by 13 days.
(Reply) (Parent) (Thread)
[User Picture]From: graceadieu
2004-02-29 07:37 pm (UTC)

:)

I was born in the early morning of March 1st in a Leap Year because my Mother didn't want me to be born on the last day of February and have that dilemma. I think I would have celebrated it on March 1st anyway, though--I used to think of myself as the Queen of March. :)
(Reply) (Thread)
[User Picture]From: grumpy_sysadmin
2004-02-29 07:55 pm (UTC)

Celebration date.

Obviously, the only appropriate thing to do is go by day-of-week in the correct ISO 8601 week.

;^>
(Reply) (Thread)
From: kristenpaige
2004-02-29 09:07 pm (UTC)
I randomly posted back in 2000 on Feb. 29th, what do I get?

I always heard if you're born on Feb. 29th, you just pick which day you want to mark as your birthday.
(Reply) (Thread)
[User Picture]From: newscane
2004-02-29 09:26 pm (UTC)
I had to write some code to do that in Java once. Forgot how I did it.

We did a story in our newscast about a baby born today... his parents say they'll celebrate on the 28th, with a special party in the leap years. He has a cousin born on 2/29 as well.
(Reply) (Thread)
[User Picture]From: disco
2004-02-29 09:36 pm (UTC)
I actually created my journal last leap year, so I guess this is the second anniversary of my journal. I didn't even realize I did this until now.
(Reply) (Thread)
[User Picture]From: daberna
2004-02-29 09:45 pm (UTC)
One of my Berekley friends is a leap year kid. Technically you'd have to wait to the 1st to be legal, but otherwise, it's best to celebrate leap year birthdays during non-leap years on both days. Seems like a good excuse to me...
(Reply) (Thread)
[User Picture]From: harrywells
2004-02-29 09:52 pm (UTC)
Isn't there going to be a February 29th and a February 30th in the year 4000? I forget why it is, but I hear that adding an extra day every 4 years is too much time, but the day they take off on every year divisible by 100 except 400, is too much, so they add the 30th on... I don't know how often that one shows up.
(Reply) (Thread)
[User Picture]From: lindsay
2004-03-01 12:53 am (UTC)
We even hung out four years ago on leap year--at least according to your journal, as I was rambling on about the "Jamboree". Silly girl :)
(Reply) (Thread)