Date::Today

(Heute gibt's Kohlrouladen!) - Neuladen, wenn dir das vorgeschlagene Essen nicht gefällt...

Version: 1.0.7

Einfaches Modul zur Ausgabe von Datum-/Zeit-Strings

Beispiele:

use strict;
use Date::Today;

my $today_de = Date::Today->new('de');
my $today_fr = Date::Today->new('fr');
my $dayname = $today_de->just_want('dayname');
my $wdaynum = $today_de->just_want('wdaynum');
my $ydaynum = $today_de->just_want('ydaynum');
my $monthname = $today_de->just_want('monthname');
my $monthnum = $today_de->just_want('monthnum');
my $dst_name = $today_de->just_want('dst_name');
my $full_year = $today_de->full_year;
my $short_year = $today_de->short_year;
my $date = $today_de->date_to_text_long;
my $prev = $today_de->prev_date_to_text_long;
my $next = $today_fr->next_date_to_text_long;
my $is_leap = $today_de->just_want('is_leap') ? "Schaltjahr" : "kein Schaltjahr";
my $now_old = $today_de->now_old;
my $date_full_year = $today_de->date_full_year;
my $date_short_year = $today_de->date_short_year;
my $sd_with_time = $today_de->date_short_year." - ".$today_de->now;
my $days_in_month = $today_de->just_want('days_in_month');
my $week_of_year = $today_de->week_of_year;
my $calendar = $today_fr->just_want('calendar');
my $today = $today_fr->just_want('mdaynum');
my $age = $today_de->get_age(1958,10,16);
my $jage = $today_de->get_age(2001,11,30);
$calendar =~ s!(\s*$today\s)!<strong style="color:red">$1</strong>!;

print "Heute ist $date - $now_old. Es ist $dst_name.\n";
print "Gestern war: $prev.\n";
print "Morgen wird: $next.\n";
print "$full_year ist $is_leap".\n";
print "Der heutige Tag ist der $ydaynum. des Jahres und der $wdaynum. der Woche!\n";
print "$date_short_year\n";
print "$date_full_year\n";
print "$sd_with_time\n";
print "Der aktuelle Monat $monthname ist der ${monthnum}te des Jahres und hat $days_in_month Tage.\n";
print "Die aktuelle Woche des Jahres ist: $week_of_year.\n";
print "Ich bin $age und mein Patenkind Jacqueline ist $jage Jahre alt.\n";
print "Monatskalender (frz.):\n";
print "<pre>\n";
print "$calendar";
print "</pre>\n";

Ausgabe:

Heute ist Freitag, 26. April 2024 - 13.45 Uhr. Es ist Sommerzeit.
Gestern war: Donnerstag, 25. April 2024.
Morgen wird: Samedi 27 avril 2024.
2024 ist Schaltjahr.
Der heutige Tag ist der 117. des Jahres und der 5. der Woche!
26.04.24
26.04.2024
26.04.24 - 13:45:48
Der aktuelle Monat April ist der 4te des Jahres und hat 30 Tage.
Die aktuelle Woche des Jahres ist: 17/2024.
Ich bin 65 und mein Patenkind Jacqueline ist 22 Jahre alt.
Monatskalender (frz.):

                Avril 2024

  Lu    Ma    Me    Je    Ve    Sa    Di  
[  1 ][  2 ][  3 ][  4 ][  5 ][  6 ][  7 ]
[  8 ][  9 ][ 10 ][ 11 ][ 12 ][ 13 ][ 14 ]
[ 15 ][ 16 ][ 17 ][ 18 ][ 19 ][ 20 ][ 21 ]
[ 22 ][ 23 ][ 24 ][ 25 ][ 26 ][ 27 ][ 28 ]
[ 29 ][ 30 ]  --    --    --    --    --  


Internationalisation:

Acht Sprachen werden unterstützt:

Default ist "en", die Auswahl erfolgt über die Objektinstanz:

 my $today_fr = Date::Today->new('fr'); 
print $today_fr->date_to_text_long;

Ausgabe: Vendredi 26 avril 2024

Beispiele:

my $today_en = Date::Today->new; # oder: Date::Today->new('en');
my $today_fr = Date::Today->new('fr');
my $today_de = Date::Today->new('de');
my $today_es = Date::Today->new('es');
my $today_pt = Date::Today->new('pt');
my $today_nl = Date::Today->new('nl');
my $today_it = Date::Today->new('it');
my $today_tr = Date::Today->new('tr');

print "EN: ", $today_en->date_to_text_long;
print "FR: ", $today_fr->date_to_text_long;
print "DE: ", $today_de->date_to_text_long;
print "ES: ", $today_es->date_to_text_long;
print "PT: ", $today_pt->date_to_text_long;
print "NL: ", $today_nl->date_to_text_long;
print "IT: ", $today_it->date_to_text_long;
print "TR: ", $today_tr->date_to_text_long;

print "EN: ", $today_en->date_short_year;
print "FR: ", $today_fr->date_short_year;
print "DE: ", $today_de->date_short_year;
print "ES: ", $today_es->date_short_year;
print "PT: ", $today_pt->date_short_year;
print "NL: ", $today_nl->date_short_year;
print "IT: ", $today_it->date_short_year;
print "TR: ", $today_tr->date_short_year;

print "EN: ", $today_en->day_and_month;
print "FR: ", $today_fr->day_and_month;
print "DE: ", $today_de->day_and_month;
print "ES: ", $today_es->day_and_month;
print "PT: ", $today_pt->day_and_month;
print "NL: ", $today_nl->day_and_month;
print "IT: ", $today_it->day_and_month;
print "TR: ", $today_tr->day_and_month;

EN: Friday, April 26th, 2024
FR: Vendredi 26 avril 2024
DE: Freitag, 26. April 2024
ES: Viernes, 26 de abril de 2024
PT: Sexta-feira, dia 26 de abril de 2024
NL: Vrijdag, 26 april 2024
IT: Venerdì, 26 Aprile 2024
TR: 26 Nisan 2024, Cuma

EN: 26/04/24
FR: 26/04/24
DE: 26.04.24
ES: 26/04/24
PT: 26/04/24
NL: 26-04-24
IT: 26/04/24
TR: 26/04/24

EN: 26/04
FR: 26/04
DE: 26.04.
ES: 26/04
PT: 26/04
NL: 26-04
IT: 26/04
TR: 26/04

Alle Methoden:

  now                            |  13:45:48
  now_short                      |  13:45
  now_old                        |  13.45 Uhr
  nowh                           |  13 h 45 min 48 s
  nowh_short                     |  13 h 45
  full_year                      |  2024
  short_year                     |  24
  about_month(year,month)        |  ARRAY(0x55637ed25288) (ARRAY REF)
  about_year(year)               |  ARRAY(0x55637ed251f8) (ARRAY REF)
  week_of_year                   |  17/2024
  day_and_month                  |  26.04.
  date_to_text_long              |  Freitag, 26. April 2024
  next_date_to_text_long         |  Samstag, 27. April 2024
  prev_date_to_text_long         |  Donnerstag, 25. April 2024
  date_short_year                |  26.04.24
  date_full_year                 |  26.04.2024
  iso8601_date                   |  2024-04-26
  iso8601_stamp                  |  2024-04-26T13:45:48+02:00
  d8_date                        |  20240426
  date_to_text_en                |  Fri, 26 Apr 2024
  three_months_calendar          |  ARRAY(0x55637ed252a0) (ARRAY REF)
  just_want('is_dst')            |  1
  just_want('dst_name')          |  Sommerzeit
  just_want('is_leap')           |  1
  get_age(byear,bmonth,bday)     |  65

  @{$today_de->three_months_calendar}   | 

                März 2024

  Mo    Di    Mi    Do    Fr    Sa    So  
  --    --    --    --  [  1 ][  2 ][  3 ]
[  4 ][  5 ][  6 ][  7 ][  8 ][  9 ][ 10 ]
[ 11 ][ 12 ][ 13 ][ 14 ][ 15 ][ 16 ][ 17 ]
[ 18 ][ 19 ][ 20 ][ 21 ][ 22 ][ 23 ][ 24 ]
[ 25 ][ 26 ][ 27 ][ 28 ][ 29 ][ 30 ][ 31 ]


                April 2024

  Mo    Di    Mi    Do    Fr    Sa    So  
[  1 ][  2 ][  3 ][  4 ][  5 ][  6 ][  7 ]
[  8 ][  9 ][ 10 ][ 11 ][ 12 ][ 13 ][ 14 ]
[ 15 ][ 16 ][ 17 ][ 18 ][ 19 ][ 20 ][ 21 ]
[ 22 ][ 23 ][ 24 ][ 25 ][ 26 ][ 27 ][ 28 ]
[ 29 ][ 30 ]  --    --    --    --    --  


                 Mai 2024

  Mo    Di    Mi    Do    Fr    Sa    So  
  --    --  [  1 ][  2 ][  3 ][  4 ][  5 ]
[  6 ][  7 ][  8 ][  9 ][ 10 ][ 11 ][ 12 ]
[ 13 ][ 14 ][ 15 ][ 16 ][ 17 ][ 18 ][ 19 ]
[ 20 ][ 21 ][ 22 ][ 23 ][ 24 ][ 25 ][ 26 ]
[ 27 ][ 28 ][ 29 ][ 30 ][ 31 ]  --    --  




  @{$today_de->about_month(2024,3)}   | 

Anzahl Tage erste Monatswoche: 7
Anzahl Tage letzte Monatswoche: 2
Erster Tag im Monat war: Montag
Letzter Tag im Monat ist: Dienstag
Anzahl Tage: 30

  @{$today_de->about_year(2024)}   | 

Anzahl Tage erste Jahreswoche: 7
Anzahl Tage letzte Jahreswoche: 2
Erster Tag im Jahr war: Montag
Letzter Tag im Jahr ist: Dienstag

  @{$today_de->about_year(2025)}[2]   | 

Neujahr 2025 ist ein Mittwoch.

just_want('noodles') -> Noodles are all I want!   ;)

Modulcode:

package Date::Today;

use strict;
use Time::Local qw/timelocal timelocal_nocheck timegm/;  ## funcs for calendar calculations and prev and next date

our $VERSION = "1.0.7";  ## Changes from 2010-01-31T13:45:00+01:00

my ($lsec,$lmin,$lhour,$lmday,$lmon,$lyear,$lwday,$lyday,$lis_dst) = localtime;   ## Today's date and time components!
my ($m, $sy, $fy) = ($lmon + 1, $lyear % 100, $lyear + 1900);
my $UTC_diff = (timegm($lsec,$lmin,$lhour,$lmday,$lmon,$lyear)
              - timelocal($lsec,$lmin,$lhour,$lmday,$lmon,$lyear))/3600;

my %daynames = (
                 en => [
                         "Sunday", "Monday", "Tuesday", "Wednesday",
                         "Thursday", "Friday", "Saturday"
                       ],
                 fr => [
                         "Dimanche", "Lundi", "Mardi", "Mercredi",
                         "Jeudi", "Vendredi", "Samedi"
                       ],
                 de => [
                         "Sonntag", "Montag", "Dienstag", "Mittwoch",
                         "Donnerstag", "Freitag", "Samstag"
                       ],
                 es => [
                         "Domingo", "Lunes", "Martes", "Miércoles",
                         "Jueves", "Viernes", "Sábado"
                       ],
                 pt => [
                         "Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira",
                         "Quinta-feira", "Sexta-feira", "Sábado"
                       ],
                 nl => [
                         "Zondag", "Maandag", "Dinsdag", "Woensdag",
                         "Donderdag", "Vrijdag", "Zaterdag"
                       ],
                 it => [
                         "Domenica", "Lunedì", "Martedì", "Mercoledì",
                         "Giovedì", "Venerdì", "Sabato"
                       ],
                 tr => [
                         "Pazar", "Pazartesi", "Salı", "Çarşamba",
                         "PerÅŸembe", "Cuma", "Cumartesi"
                       ],
            );

my %monthnames = (
                 en => [
                         "January", "February", "March", "April", "May", "June",
                         "July", "August", "September", "October", "November", "December"
                       ],
                 fr => [
                         "Janvier", "Février", "Mars", "Avril", "Mai", "Juin",
                         "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"
                       ],
                 de => [
                         "Januar", "Februar", "März", "April", "Mai", "Juni",
                         "Juli", "August", "September", "Oktober", "November", "Dezember"
                       ],
                 es => [
                         "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio",
                         "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"
                       ],
                 pt => [
                         "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho",
                         "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"
                       ],
                 nl => [
                         "Januari", "Februari", "Maart", "April", "Mei", "Juni",
                         "Juli", "Augustus", "September", "October", "November", "December"
                       ],
                 it => [
                         "Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno",
                         "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"
                       ],
                 tr => [
                         "Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran",
                         "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"
                       ],
            );

my %dst_name = (
         en => ["daylight saving time", "winter time"],
         fr => ["heure d'été", "heure d'hiver"],
         de => ["Sommerzeit", "Winterzeit"],
         es => ["horario de verano", "horario de invierno"],
         pt => ["horário de verão", "horário de inverno"],
         nl => ["zomertijd", "wintertijd"],
         it => ["ora estiva", "ora invernale"],
         tr => ["Yaz Saati", "Kış Saati"],
        );

my @days_in_month = (31,28,31,30,31,30,31,31,30,31,30,31);

## object constructor
sub new {
  my $pkg = shift;
  my $today = bless { lang => shift || 'en' }, $pkg;
  return $today;
}

###### private functions
## returns language-appropriate delimiter for short date format
my $del = sub {
    my $lang = shift;
    return $lang eq 'de' ? "." : $lang eq 'nl' ? "-" : "/";
  };

## returns language-appropriate long date format
my $long_date_format = sub {
    my ($lang, $dayname, $day, $monthname, $year) = @_;
    my @lc_langs = qw(fr es pt nl);      ## languages in which monthnames are written lowercase
    for (@lc_langs) {
      $monthname = lcfirst $monthname if $lang eq $_;
    }
    my $suffix = $day =~ /^[^1]?1$/ ? 'st'              ## ordinal suffix for english date format
               : $day =~ /^[^1]?2$/ ? 'nd'
               : $day =~ /^[^1]?3$/ ? 'rd' : 'th';
    my %format = (
               en => "$dayname, $monthname $day".$suffix.", $year",
               fr => "$dayname $day $monthname $year",
               de => "$dayname, $day. $monthname $year",
               es => "$dayname, $day de $monthname de $year",
               pt => "$dayname, dia $day de $monthname de $year",
               nl => "$dayname, $day $monthname $year",
               it => "$dayname, $day $monthname $year",
               tr => "$day $monthname $year, $dayname"
               );
    return $format{$lang};
  };

## returns english abbreviations for month name and day name
my $en_abbr = sub {
    return [map { substr($_, 0, 3) } ($monthnames{'en'}->[$lmon],$daynames{'en'}->[$lwday])];
  };

## checks if year is leap year (1) or not (0)
my $is_leap  = sub {
    my $year = shift;
    if ($year % 4 == 0 && ($year % 400 == 0 || $year % 100 != 0)) { 
      return 1;
    } else { return 0; }
  };

## returns number of days in month
my $days_in_month = sub {
    my ($year, $month) = @_;
    return ($is_leap->($year+1900) && $month == 1) ? 29 : $days_in_month[$month];
  };

## get required data for prev_date_to_text_long
my $prev = sub {
    my $lang = shift;
    my ($day, $month, $year, $wday) = (localtime timelocal_nocheck 0,0,0,$lmday-1,$lmon,$lyear)[3,4,5,6]; 
    my $dayname = $daynames{$lang}->[$wday];
    $year += 1900;
    return [$year, $month, $day, $dayname];
  };

## dito but for next_date_to_text_long
my $next = sub {
    my $lang = shift;
    my ($day, $month, $year, $wday) = (localtime timelocal_nocheck 0,0,0,$lmday+1,$lmon,$lyear)[3,4,5,6];
    my $dayname = $daynames{$lang}->[$wday];
    $year += 1900;
    return [$year, $month, $day, $dayname];
  };

## if you mean, this one sub looks like Randal L. Schwartz's calendar sub... you're right! ;)
my $cal = sub {
    my $lang = shift;
    my ($year, $monthname, $nod_fw, $d) = @_;
    $year += 1900;
    my $str;
    my $curday = 1+($nod_fw-7);
    $str = ' ' x ((43-length("$monthname $year")) / 2)."$monthname $year\n\n";
    my @day_abbr = map { sprintf " %3.2s  ", $daynames{$lang}->[$_] } 1..6,0;
    foreach my $abbr (@day_abbr) { $str .= $abbr; }
    $str .= "\n";
    {
      for ($curday..($curday+6)) {
        if ($_ < 1) {
          $str .= "  --  ";
        } elsif ($_ <= $d) {
          $str .= sprintf "[ %2d ]", $_;
        } else {
          $str .= "  --  ";
        }
      }
      $str .= "\n";
      $curday += 7;
      redo if $curday <= $d;
    }
    return $str."\n";
  };

## returns 'week day' for given day
my $get_wday = sub {
    my ($year, $month, $day) = @_;
    return (localtime(timelocal 0,0,0,$day,$month,$year))[6];
  };

## returns 'week number' for sub 'week_of_year' (works like Date::Calc's 'Week_Number')
my $get_weeks = sub {
    my $year = shift;
    my $first_wday = $get_wday->($year, 0, 1);
    my $last_wday = $get_wday->($year, 11, 31);
    return 52 + ((($first_wday == 4) || ($last_wday  == 4) ) ? 1 : 0);
  };

###### public functions
#### today's time functions
sub now {
  return sprintf("%02d:%02d:%02d", $lhour, $lmin, $lsec);
}

sub now_short {
  return sprintf("%02d:%02d", $lhour, $lmin);
}

## Use now_old with german language only!
sub now_old {
  return sprintf("%02d.%02d %s", $lhour, $lmin, "Uhr") if $_[0]->{lang} eq 'de';
    die "'now_old': Usage only with language set to german: '".__PACKAGE__."->new('de')'";
}

## Use nowh and nowh_short with french language only!
sub nowh {
  if ($_[0]->{lang} eq 'fr') {
    if ($lmin == 0 && $lsec == 0) {
      my $h = $lhour <= 1 ? "heure" : "heures";
      return "$lhour $h";
    } elsif ($lsec == 0) {
        return "$lhour h $lmin";
    } else {
      return "$lhour h $lmin min $lsec s";
    }
  } else {
    die "'nowh': Usage only with language set to french: '".__PACKAGE__."->new('fr')'";
  }   
}

sub nowh_short {
  if ($_[0]->{lang} eq 'fr') {
    if ($lmin == 0) {
      my $h = $lhour <= 1 ? "heure" : "heures";
      return "$lhour $h";
    } else {
      return "$lhour h $lmin";
    }
  } else {
    die "'nowh_short': Usage only with language set to french: '".__PACKAGE__."->new('fr')'";
  }   
}

#### today's date functions
sub full_year {
  return $fy;                    ## 4 digits
}

sub short_year {
  return sprintf("%02d", $sy);   ## 2 digits
}

## about_month returns number of days of first and last week,
## dayname of first and last day, number of days in month
sub about_month {
  my ($today, $year, $month) = @_;
  my $nod = $days_in_month->($year, $month);
  my $first_wday = $get_wday->($year, $month, 1);
  my $last_wday = $get_wday->($year, $month, $nod);
  my $nod_fw = $first_wday > 0 ? (7 - $first_wday) + 1 : 1;
  my $nod_lw = $last_wday == 0 ? 7 : $last_wday;
  my $first = $daynames{$today->{lang}}[$first_wday];
  my $last = $daynames{$today->{lang}}[$last_wday];
  return [$nod_fw, $nod_lw, $first, $last, $nod];
}

## about_year returns number of days of first and last week,
## dayname of first and last day of year
sub about_year {
  my ($today, $year) = @_;
  my $first_wday = $get_wday->($year, 0, 1);
  my $last_wday = $get_wday->($year, 11, 31);
  my $nod_fw = $first_wday > 0 ? (7 - $first_wday) + 1 : 1;
  my $nod_lw = $last_wday == 0 ? 7 : $last_wday;
  my $first = $daynames{$today->{lang}}[$first_wday];
  my $last = $daynames{$today->{lang}}[$last_wday];
  return [$nod_fw, $nod_lw, $first, $last];
}

## returns week of year respecting iso 8601 (e.g. 24/2008 or 53/2009)
sub week_of_year {
  my $year = $lyear;
  my $first_wday = $get_wday->($year, 0, 1);
  my $tmp = int (($lyday + $first_wday) / 7);
  $tmp-- if $tmp == ($lyday + $first_wday) / 7;
  my $num = $tmp + (($first_wday <= 4) ? 1 : 0);
  my $week_of_year = $num == 0 ? $get_weeks->($year-1)."/".($fy-1)
                   : $num > $get_weeks->($year) ? "1/".($fy+1) : $num."/".$fy;
  return $week_of_year;
}

## returns day and month in language-appropriate format (e.g. 11/06, 11-06 or 11.06.)
sub day_and_month {
  my $lang = $_[0]->{lang};
  my $str = sprintf("%02d".$del->($lang)."%02d", $lmday, $m);
  $str .= $del->($lang) if $lang eq 'de';
  return $str;
}

## date_to_text_long returns date in language-appropriate long format (e.g. Wednesday, June 11th 2008,
## Mittwoch, 11. Juni 2008)
sub date_to_text_long {
  my $lang = $_[0]->{lang};
  return $long_date_format->($lang, $daynames{$lang}->[$lwday], $lmday, $monthnames{$lang}->[$lmon], $fy);
}

## yesterday's date
sub prev_date_to_text_long {
  my $lang = $_[0]->{lang};
  my ($year, $month, $day, $dayname) = @{$prev->($lang)};
  return $long_date_format->($lang, $dayname, $day, $monthnames{$lang}->[$month], $year);
}

## tomorrow's date
sub next_date_to_text_long {
  my $lang = $_[0]->{lang};
  my ($year, $month, $day, $dayname) = @{$next->($lang)};
  return $long_date_format->($lang, $dayname, $day, $monthnames{$lang}->[$month], $year);
}

## returns date in short format (e.g. 11/06/08)
sub date_short_year {
  my $lang = $_[0]->{lang};
  return sprintf("%02d".$del->($lang)."%02d".$del->($lang)."%02d", $lmday, $m, $sy);
}

## returns date in short format but 4-digits-year (e.g. 11/06/2008)
sub date_full_year {
  my $lang = $_[0]->{lang};
  return sprintf("%02d".$del->($lang)."%02d".$del->($lang)."%04d", $lmday, $m, $fy);
}

## iso8601_date respects ISO 8601 (e.g. 2008-06-11)
sub iso8601_date {
  return sprintf("%04d-%02d-%02d", $fy, $m, $lmday);
}

## returns full time stamp (e.g. 2008-06-11T12:34:56+02:00)
sub iso8601_stamp {
  my $diff = sprintf("%02d", $UTC_diff);
  return $_[0]->iso8601_date."T".$_[0]->now."+".$diff.":00";
}

## just returns 8-digits-date (e.g. 20080611)
sub d8_date {
  return sprintf("%04d%02d%02d", $fy, $m, $lmday);
}

## today's date with english abbreviations (e.g. Wed, 11 Jun 2008)
sub date_to_text_en {
  my ($month, $day) = @{&$en_abbr};
  return "$day, $lmday $month ".$fy;
}

## returns a three months calendar (previous, this and next month)
sub three_months_calendar {
  my $lang = $_[0]->{lang};
  my ($pmon,$pyear) = (localtime timelocal_nocheck 0,0,0,-1,$lmon,$lyear)[4,5];   
  my ($nmon,$nyear) = (localtime timelocal_nocheck 0,0,0,$days_in_month->($lyear, $lmon)+1,$lmon,$lyear)[4,5];
  my @this = ($lyear, $monthnames{$lang}->[$lmon], @{$_[0]->about_month($lyear, $lmon)}[0,4]);
  my @prev = ($pyear, $monthnames{$lang}->[$pmon], @{$_[0]->about_month($pyear, $pmon)}[0,4]);
  my @next = ($nyear, $monthnames{$lang}->[$nmon], @{$_[0]->about_month($nyear, $nmon)}[0,4]);
  return [$cal->($lang, @prev), $cal->($lang, @this), $cal->($lang, @next)];
}

## returns the age of a person by known birthyear, birthmonth, birthday
sub get_age {
  my ($today, $birthyear, $birthmonth, $birthday) = @_;
  my $age = timelocal(0,0,0,$birthday,$birthmonth-1,$lyear) > time ? $fy - $birthyear - 1 : $fy - $birthyear;
  return $age;
}

## funny sub to get all you just want today!
sub just_want {
  my ($today, $wanted) = @_;
  my $lang = $today->{lang};
  my %dt_parts = (
                dayname        => $daynames{$lang}->[$lwday],
                day_en_abbr    => &$en_abbr->[1],
                wdaynum        => $lwday == 0 ? 7 : $lwday,
                mdaynum        => $lmday,
                ydaynum        => $lyday + 1,
                monthname      => $monthnames{$lang}->[$lmon],
                month_en_abbr  => &$en_abbr->[0],
                monthnum       => $m,
                is_dst         => $lis_dst,
                dst_name       => $lis_dst ? $dst_name{$lang}->[0] : $dst_name{$lang}->[1],
                is_leap        => $is_leap->($lyear),
                days_in_month  => $days_in_month->($lyear, $lmon),
                next_array     => $next->($lang),
                prev_array     => $prev->($lang),
                calendar       => $today->three_months_calendar->[1],
                noodles        => "Noodles are all I want!",
               );
  return $dt_parts{$wanted};
}

sub version {
  return $VERSION;
}

1;

Modul-Dokumentation (POD):

-------------------- Die POD ist noch unvollständig! Mail-Adresse und URL unter AUTHOR existieren noch nicht! --------------------

=head1 NAME

Date::Today - Just provides date and time strings from today's date and time in a simple OOish way. For elaborate date calculations please use Date::Calc or Date::Pcalc.

=head1 MOTTO

$today->just_want('noodles');

=head1 SYNOPSIS

  use Date::Today;

  $today = new Date::Today;		# english, default
  $today_fr = new Date::Today('fr');	# french
  $today_nl = Date::Today->new('nl');	# netherlands

  $date_to_text_long = $today_nl->date_to_text_long;
  $next_date_to_text_long = $today_nl->next_date_to_text_long;

  $nowh = $today_fr->nowh;

  $iso8601_date = $today->iso8601_date;

  $d8_date = $today->d8_date;

  $today->just_want('dayname');

  $version = $today->version;
  $version = $Date::Today::VERSION;

See METHODS below for more.

=head1 DESCRIPTION

Date::Today is a very small module which provides differently formatted strings for today's date and time. Use it for web pages whenever you need to display the date, the time, a time stamp, etc.

=over 2

=item *

C<use Date::Today;>

=item *

C<$today = new Date::Today;>

Creates a new instance of object C<Today>. If no language specified, language is set to C<en> (english).

=item *

C<$today = Date::Today-E<gt>new('fr');>

Creates a new instance of object C<Today>. Language is set to french (C<fr>). You can create another object for each other language:

    $today_fr = Date::Today->new('fr');	# french
    $today_de = Date::Today->new('de');	# german
    $today_es = Date::Today->new('es');	# spanish

=item *

C<$today-E<gt>now>

Calls method C<now> which just returns today's time.

=back

The original distribution supports actually seven languages:

	en - English    (default)
	fr - Français   (french)
	de - Deutsch    (german)
	es - Español    (spanish)
	pt - Português  (Portuguese)
	nl - Nederlands (Dutch)
	it - Italiano   (Italian)

See ADD LANGUAGE below for how to install an additional language

=head1 METHODS

=over 2

=item *

C<$today-E<gt>now>

Returns full time (HH:MM::SS):

    $now = $today->now;
    print $now;
	# 12:34:56

=item *

C<$today-E<gt>now_short>

Returns time without seconds (HH:MM):

    $now_short = $today->now_short;
    print $now_short;
	# 12:34

C<$today-E<gt>now_old>

Use with german language (C<de>) only! Returns old german form of displaying time (HH.MM Uhr):

    $now_old = $today_de->now_old;
    print $now_old;
	# 12.34 Uhr

C<$today-E<gt>nowh>

Use with french language (C<fr>) only! Returns specific form of writing time data in french texts:

    $nowh = $today_fr->nowh;
    print $nowh;
	# 12 h 59 min 59 s
	# if minuts and seconds are both 0, returns:
	# 13 heures.
	# if hour <= 1, returns:
	# 0 heure (or: 1 heure)
	# if seconds are 0, returns:
	# 13 h 1

C<$today-E<gt>nowh_short>

Use with french language (C<fr>) only! Short form of C<nowh>:

    $nowh_short = $today_fr->nowh_short;
    print $nowh_short;
	# 12 h 59
	# if minuts are 0, returns:
	# 13 heures.
	# if hour <= 1, returns:
	# 0 heure (or: 1 heure)

C<$today-E<gt>full_year>

Returns four-digits-year (YYYY).

C<$today-E<gt>short_year>

Returns two-digits-year (YY).

C<$today-E<gt>day_and_month>

Returns short date format with just day and month. Delimiter is language-appropriate:

    $dm = $today->day_and_month;
    print $day_and_month;
	# 12/06

    $dm_de = $today_de->day_and_month;
    print $day_and_month;
	# 12.06.

    $dm_nl = $today_nl->day_and_month;
    print $day_and_month;
	# 12-06

C<$today-E<gt>date_to_text_long>

Returns long date (day name, (D)D month name YYYY) in language-appropriate format:

    $date_to_text_long = $today->date_to_text_long;
    print $date_to_text_long;
	# Thursday, June 12th 2008

    $long_date_de = $today_de->date_to_text_long;
    print $long_date_de;
	# Donnerstag, 12. Juni 2008

    $long_date_fr = $today_fr->date_to_text_long;
    print $long_date_fr;
	# Jeudi 12 juin 2008

C<$today-E<gt>next_date_to_text_long>

Same as above, but with tomorrow's date.

C<$today-E<gt>next_date_to_text_long>

Same as C<date_to_text_long>, but with yesterday's date.

C<$today-E<gt>date_short_year>

Returns short date with two-digits-year (DD/MM/YY). Delimiter is language-appropriate:

    $xshort = $today->date_short_year;
    print $xshort;
	# 12/06/08

    $xshort_de = $today_de->date_short_year;
    print $xshort_de;
	# 12.06.08

    $xshort_nl = $today_nl->date_short_year;
    print $xshort_nl;
	# 12-06-08

C<$today-E<gt>date_full_year>

Same as above, but with four-digits-year (DD/MM/YYYY).

C<$today-E<gt>iso8601_date>

Returns short date respecting ISO 8601 norm (YYYY-MM-DD).

C<$today-E<gt>iso8601_stamp>

Returns a full ISO 8601 timestamp (YYYY-MM-DDTHH:MM:SS+hh:mm). C<+hh:mm> represents the difference between your time zone and UTC (default value: +1 for difference to UTC in central europe winter time). You should change the scalar value of C<$UTC_diff> to this value after having copied this module if you need this method.

C<$today-E<gt>date_to_text_en>

Returns date with english day and month name abbreviations (day abbr, (D)D month abbr YYYY). For example, use it for C<lastBuildDate> in RSS feeds:

    $lBD = $today->date_to_text_en;
    print $lBD ;           # Thu, 12 June 2008

    $lastBD = $lBD." ".$today->now." EST";
    print $lastBD;         # Thu, 12 June 2008 12:34:56 EST

    print "<lastBuildDate>$lastBD</lastBuilDate>\n";
    # <lastBuildDate>Thu, 12 June 2008 12:34:56 EST</lastBuilDate>

=back

=head1 ADD LANGUAGE

Edit file C<Today.pm> doing the following:

Add a new key to the bottom of hash %daynames. Key name should be the two-letters international code for your new language.
Set the value in an anonymous array C<[ ... ]>. Example:

	xx => [ "xxnamefor_sunday", "xxnamefor_monday",
                "xxnamefor_tuesday", "xxnamefor_wednesday",
                "xxnamefor_thirsday", "xxnamefor_friday",
                "xxnamefor_saturday"
              ],

Add a new key to the bottom of hash %monthnames with your international code and set month name values proceeding like above.

Add a new key to the bottom of hash %dst with your international code and set the value to a 2 elements anonymous array with the translation of C<summertime> and C<wintertime>:

	xx => [ "xxidiom for summertime", "xx for winter time"],

Add a new key to the bottom of hash %format (in private sub C<long_date_format>) with your international code and set the value to the long date format in use by your language.

If in your language month names are generally written lowercase, add the international code corresponding to your language in array @lc_langs (you'll find it also in sub C<long_date_format>).


=head1 BUGS

No bugs known. If you find one, don't throw it away! Send it to me (please see AUTHOR below).

=head1 SEE ALSO

Date::Calc by Steffen Beyer for elaborate date calculations.

Date::Pcalc by J. David Eisenberg and Steffen Beyer. Date::Pcalc is a C<Perl translation> of Steffen's Date::Calc, which was written in C.

ISO 8601: L<http://www.iso.org/iso/support/faqs/faqs_widely_used_standards/widely_used_standards_other/date_and_time_format.htm>

=head1 AUTHOR

Patrick Andrieu

mailto:date.today@atomic-eggs.com
http://www.atomic-eggs.com/cwi/perl/scripts/nobody/needs

=head1 COPYRIGHT

 Copyright (c) 2008 by Patrick Andrieu
 All rights reserved.

=head1 LICENSE

This package is free software; you can redistribute it and/or
modify it under the same terms as Perl itself, i.e., under the
terms of the "Artistic License" or the "GNU General Public License".