… | |
… | |
30 | package Linux::DVB; |
30 | package Linux::DVB; |
31 | |
31 | |
32 | use Fcntl (); |
32 | use Fcntl (); |
33 | |
33 | |
34 | BEGIN { |
34 | BEGIN { |
35 | $VERSION = '0.3'; |
35 | $VERSION = '0.4'; |
36 | @ISA = qw(Exporter); |
36 | @ISA = qw(Exporter); |
37 | |
37 | |
38 | require XSLoader; |
38 | require XSLoader; |
39 | XSLoader::load __PACKAGE__, $VERSION; |
39 | XSLoader::load __PACKAGE__, $VERSION; |
40 | |
40 | |
… | |
… | |
463 | Break down a "DVB time" (modified julian date + bcd encoded seconds) into |
463 | Break down a "DVB time" (modified julian date + bcd encoded seconds) into |
464 | it's components (non-C<_linear>) or into a seconds count (C<_linear> |
464 | it's components (non-C<_linear>) or into a seconds count (C<_linear> |
465 | variants) since the epoch (C<datetime_linear>) or the start of the day |
465 | variants) since the epoch (C<datetime_linear>) or the start of the day |
466 | (C<time_linear>). |
466 | (C<time_linear>). |
467 | |
467 | |
|
|
468 | The format of the returns value of the date and datetime functions is |
|
|
469 | I<not> compatible with C<Time::Local>. Use the C<_linear> functions |
|
|
470 | instead. |
|
|
471 | |
468 | Example: |
472 | Example: |
469 | |
473 | |
470 | my $time = Linux::DVB::Decode::datetime_linear $mjd, $hms |
474 | my $time = Linux::DVB::Decode::datetime_linear $mjd, $hms |
471 | printf "Starts at %s\n", |
475 | printf "Starts at %s\n", |
472 | POSIX::strftime "%Y-%m-%d %H:%M:%S", |
476 | POSIX::strftime "%Y-%m-%d %H:%M:%S", |
… | |
… | |
488 | sub date($) { |
492 | sub date($) { |
489 | my ($mjd) = @_; |
493 | my ($mjd) = @_; |
490 | |
494 | |
491 | # Date is given in Modified Julian Date |
495 | # Date is given in Modified Julian Date |
492 | # Decoding routines taken from ANNEX C, ETSI EN 300 468 (DVB SI) |
496 | # Decoding routines taken from ANNEX C, ETSI EN 300 468 (DVB SI) |
493 | my $y_ = int ($mjd - 15078.2) / 365.25; |
497 | my $y_ = int (($mjd - 15078.2) / 365.25); |
494 | my $m_ = int (($mjd - 14956.1 - int ($y_ * 365.25)) / 30.6001); |
498 | my $m_ = int (($mjd - 14956.1 - int ($y_ * 365.25)) / 30.6001); |
495 | my $day = $mjd - 14956 - int ($y_ * 365.25) - int ($m_ * 30.6001); |
499 | my $day = $mjd - 14956 - int ($y_ * 365.25) - int ($m_ * 30.6001); |
496 | my $k = $m_ == 14 or $m_ == 15 ? 1 : 0; |
500 | my $k = $m_ == 14 or $m_ == 15 ? 1 : 0; |
497 | my $year = $y_ + $k + 1900; |
501 | my $year = $y_ + $k + 1900; |
498 | my $month = $m_ - 1 - $k * 12; |
502 | my $month = $m_ - 1 - $k * 12; |
… | |
… | |
509 | |
513 | |
510 | (($h * 60) + $m * 60) + $s |
514 | (($h * 60) + $m * 60) + $s |
511 | } |
515 | } |
512 | |
516 | |
513 | sub datetime_linear($$) { |
517 | sub datetime_linear($$) { |
|
|
518 | my ($sec, $min, $hour, $mday, $mon, $year) = |
|
|
519 | Linux::DVB::Decode::datetime $_[0], $_[1]; |
|
|
520 | |
514 | require Time::Local; |
521 | require Time::Local; |
515 | Time::Local::timegm (Linux::DVB::Decode::datetime $_[0], $_[1]) |
522 | Time::Local::timegm ($sec, $min, $hour, $mday, $mon - 1, $year) |
516 | } |
523 | } |
517 | |
524 | |
518 | =back |
525 | =back |
519 | |
526 | |
520 | =head1 AUTHORS |
527 | =head1 AUTHORS |