ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # some routines taken from wiki.pl to help debug: it translates Perl
  2. # times into human readable times
  3. sub CalcDay {
  4. my ($sec, $min, $hour, $mday, $mon, $year) = gmtime(shift);
  5. return sprintf('%4d-%02d-%02d', $year+1900, $mon+1, $mday);
  6. }
  7. sub CalcTime {
  8. my ($sec, $min, $hour, $mday, $mon, $year) = gmtime(shift);
  9. return sprintf('%02d:%02d:%02d UTC', $hour, $min, $sec);
  10. }
  11. sub CalcTimeSince {
  12. my $total = shift;
  13. if ($total >= 7200) {
  14. return Ts('%s hours ago',int($total/3600));
  15. } elsif ($total >= 3600) {
  16. return T('1 hour ago');
  17. } elsif ($total >= 120) {
  18. return Ts('%s minutes ago',int($total/60));
  19. } elsif ($total >= 60) {
  20. return T('1 minute ago');
  21. } elsif ($total >= 2) {
  22. return Ts('%s seconds ago',int($total));
  23. } elsif ($total == 1) {
  24. return T('1 second ago');
  25. } else {
  26. return T('just now');
  27. }
  28. }
  29. sub TimeToText {
  30. my $t = shift;
  31. return CalcDay($t) . ' ' . CalcTime($t);
  32. }
  33. # Complete date plus hours and minutes: YYYY-MM-DDThh:mmTZD (eg
  34. # 1997-07-16T19:20+01:00)
  35. sub TimeToW3 {
  36. my ($sec, $min, $hour, $mday, $mon, $year) = gmtime(shift);
  37. # use special UTC designator ("Z")
  38. return sprintf('%4d-%02d-%02dT%02d:%02dZ', $year+1900, $mon+1, $mday, $hour, $min);
  39. }
  40. sub TimeToRFC822 {
  41. my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime(shift);
  42. # Sat, 07 Sep 2002 00:00:01 GMT
  43. return sprintf("%s, %02d %s %04d %02d:%02d:%02d GMT",
  44. qw(Sun Mon Tue Wed Thu Fri Sat)[$wday], $mday,
  45. qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)[$mon],
  46. $year+1900, $hour, $min, $sec);
  47. }
  48. while(<>) {
  49. s/(\d\d\d\d\d+)/TimeToText($1)/ge;
  50. print;
  51. }