Date-Discordian

 view release on metacpan or  search on metacpan

lib/Date/Discordian.pm  view on Meta::CPAN

# sub from_discordian {{{

sub from_discordian {    # You only think it's possible.
    my $discordian = shift;
    my $epoch;

    for ($discordian) {

        # The day does not really matter ...
        s/sweetmorn|boomtime|setting orange|prickle prickle|pungenday//i;
        s/,//g;
        s/YOLD//i;
        s/\s+/ /g;
        s/\(.*?\)//;    # Holydays
        s/^\s+//;
    }

    # Special case - St. Tibb's Day
    if ( $discordian =~ /st\.? tibb'?s day/i ) {
        $discordian =~ m/(\d{4})/;
        my $year = $1;
        $year -= 1166;
        $epoch = timegm( 0, 0, 0, 29, 1, $year );
      } else {

        # With any luck, we now have "season day year"
        my ( $season, $day, $year ) = split / /, $discordian;
        $year -= 1166;
        $season = lc($season);
        my %seasons = (
          chaos       => 0,
          discord     => 1,
          confusion   => 2,
          bureaucracy => 3,
          aftermath   => 4
        );
        my $doy = $seasons{$season} * 73 + $day;
        $doy++ if ( $doy >= 60 && Date::Leapyear::isleap($year) );
        $epoch = ( $doy - 1 ) * 86400 + timegm( 0, 0, 0, 1, 0, $year );
    }

    return $epoch;
}    #}}}

# sub season {{{

sub season {    # For everything, there is a season.
    my $d = shift;
    my $h;

    if ( ref $d ) {
        $h = discohash( $d->year, $d->month, $d->day );
      } else {
        $h = to_discordian($d);
    }
    return $h->{season};    # turn, turn, turn
}    #}}}

# sub discoday {{{

sub discoday {    # Stayin' alive
    my $d = shift;
    my $h;

    if ( ref $d ) {
        $h = discohash( $d->year, $d->month, $d->day );
        return $h->{discoday};
      } else {
        $h = to_discordian($d);
        return $h->{discoday};
    }
}    # }}}

# sub yold {{{

sub yold {

    # Some folks say the epoch begins in 4000 BC. This is heresy. Spurn
    # these people. Or at least make strange chicken noises at them.

    my $d = shift;
    my $h;

    if ( ref $d ) {
        $h = discohash( $d->year, $d->month, $d->day );
        return $h->{yold};
      } else {
        $h = to_discordian($d);
        return $h->{yold};
    }
}    #}}}

# sub holyday {{{

sub holyday {    # Eat a hot dog
    my $d = shift;
    my $h;

    if ( ref $d ) {
        $h = discohash( $d->year, $d->month, $d->day );
        return $h->{holyday};
      } else {
        $h = to_discordian($d);
        return $h->{holyday};
    }
}    #}}}

'Hail Eris!';

# Docs {{{

=head1 NAME

Date::Discordian - Calculate the Discordian date of a particular day

=head1 SYNOPSIS

  use Date::Discordian;
  $discordian = discordian(time);
  $epochtime = inverse_discordian('bureaucracy 47, 3166');



( run in 2.246 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )