ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Linux-DVB/DVB.pm
(Generate patch)

Comparing Linux-DVB/DVB.pm (file contents):
Revision 1.7 by root, Mon Apr 11 21:14:12 2005 UTC vs.
Revision 1.8 by root, Tue Apr 12 00:54:57 2005 UTC

448 0x2 => 'unpublished', 448 0x2 => 'unpublished',
449 0x3 => 'live broadcast', 449 0x3 => 'live broadcast',
450 }, 450 },
451); 451);
452 452
453=item ($sec,$min,$hour) = Linux::DVB::Decode::time $hms
454
455=item ($mday,$mon,$year) = Linux::DVB::Decode::date $mjd
456
453=item ($sec,$min,$hour,$mday,$mon,$year) = Linux::DVB::Decode::time $mjd, $time 457=item ($sec,$min,$hour,$mday,$mon,$year) = Linux::DVB::Decode::datetime $mjd, $hms
458
459=item $sec = Linux::DVB::Decode::time_linear $hms
460
461=item $sec = Linux::DVB::Decode::datetime_linear $mjd, $hms
454 462
455Break down a "DVB time" (modified julian date + bcd encoded seconds) into 463Break down a "DVB time" (modified julian date + bcd encoded seconds) into
456it's components in UTC (i.e. use Time::Local::timegm to convert to UNIX 464it's components (non-C<_linear>) or into a seconds count (C<_linear>
457time). 465variants) since the epoch (C<datetime_linear>) or the start of the day
466(C<time_linear>).
458 467
459=cut 468Example:
460 469
470 my $time = Linux::DVB::Decode::datetime_linear $mjd, $hms
471 printf "Starts at %s\n",
472 POSIX::strftime "%Y-%m-%d %H:%M:%S",
473 localtime $time;
474
475=cut
476
461sub time($$) { 477sub time($) {
462 my ($mjd, $time) = @_; 478 my ($time) = @_;
479
480 # Time is in UTC, 24 bit, every nibble one digit in BCD from right to left
481 my $hour = sprintf "%02x", ($time >> 16) & 0xFF;
482 my $minute = sprintf "%02x", ($time >> 8) & 0xFF;
483 my $second = sprintf "%02x", ($time ) & 0xFF;
484
485 ($second, $minute, $hour)
486}
487
488sub date($) {
489 my ($mjd) = @_;
463 490
464 # Date is given in Modified Julian Date 491 # Date is given in Modified Julian Date
465 # Decoding routines taken from ANNEX C, ETSI EN 300 468 (DVB SI) 492 # Decoding routines taken from ANNEX C, ETSI EN 300 468 (DVB SI)
466 my $y_ = int ($mjd - 15078.2) / 365.25; 493 my $y_ = int ($mjd - 15078.2) / 365.25;
467 my $m_ = int (($mjd - 14956.1 - int ($y_ * 365.25)) / 30.6001); 494 my $m_ = int (($mjd - 14956.1 - int ($y_ * 365.25)) / 30.6001);
468 my $day = $mjd - 14956 - int ($y_ * 365.25) - int ($m_ * 30.6001); 495 my $day = $mjd - 14956 - int ($y_ * 365.25) - int ($m_ * 30.6001);
469 my $k = $m_ == 14 or $m_ == 15 ? 1 : 0; 496 my $k = $m_ == 14 or $m_ == 15 ? 1 : 0;
470 my $year = $y_ + $k + 1900; 497 my $year = $y_ + $k + 1900;
471 my $month = $m_ - 1 - $k * 12; 498 my $month = $m_ - 1 - $k * 12;
472 499
473 # Time is in UTC, 24 bit, every nibble one digit in BCD from right to left 500 ($day, $month, $year)
474 my $hour = sprintf "%02x", ($time >> 16) & 0xFF; 501}
475 my $minute = sprintf "%02x", ($time >> 8) & 0xFF;
476 my $second = sprintf "%02x", ($time ) & 0xFF;
477 502
478 return ($second, $minute, $hour, $day, $month, $year); 503sub datetime($$) {
504 (Linux::DVB::Decode::time $_[1], date $_[0])
505}
506
507sub time_linear($) {
508 my ($s, $m, $h) = Linux::DVB::Decode::time $_[0];
509
510 (($h * 60) + $m * 60) + $s
511}
512
513sub datetime_linear($$) {
514 require Time::Local;
515 Time::Local::timegm (Linux::DVB::Decode::datetime $_[0], $_[1])
479} 516}
480 517
481=back 518=back
482 519
483=head1 AUTHORS 520=head1 AUTHORS

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines