Ticket #89 (new enhancement)

Opened 4 years ago

Last modified 4 years ago

strftime does not have %z

Reported by: bmikeb@… Owned by:
Priority: minor Milestone:
Component: Shepherd Version: 1.x
Keywords: Cc:

Description

.shepherd/reconcilers/reconciler_mk2/reconciler_mk2 line 635, <> line 1. : /Users/abuse/.shepherd/grabbers/yahoo7widget/output-0.xmltv: Use of uninitialized value $tzstring in int at

if (!$gmt_offset) {

my $tzstring = strftime("%z", localtime(time));

Not all strftime's support "%z" or have Timezone information. In my case, no bytes are returned from strftime causing an error. This also occurs in YahooWidget? and in Common.pl where the %z option is used. Manual substituting of $tzstring = "+1000" cured incorrect times for shows. See http://opengroup.org/onlinepubs/007908799/xsh/strftime.html Need another way to aquire the timezone offset.

mac osx bsd darwin perl 5.10

Change History

Changed 4 years ago by paulx@…

  • priority changed from major to minor
  • type changed from defect to enhancement

While interesting, unless someone can recommend a supported way for this information, we can't change our code.

Changed 4 years ago by MikeB

The strftime problem has gone away for me. I am also running an old Mac. Newer Mac's most likely have the updated strftime, but....

I ended up downloading the source code for strftime.c, hacking the Perl 5.10 code and added it into both Timepiece and the perl library.dyld instead of the strftime calling he Mac Library. Then I recompiled the Perl.

Yea, it took a while! (mostly learning!). Other than that you may consider not using the "z" option. You may calculate the timezone offset by:

# Calculate the offset in seconds that we are from UTC.
# This code taken from the Time::Timezone Perl package,
# written by Graham Barr <bodg@tiuk.ti.com>,
# David Muir Sharnoff <muir@idiom.com> and
# Paul Foley <paul@ascent.com>
#
sub Calc_Off($)
{
        my ($time) = $_[0];
        my (@l) = localtime($time);
        my (@g) = gmtime($time);
        my $off;

        $off =     $l[0] - $g[0]
                + ($l[1] - $g[1]) * 60
                + ($l[2] - $g[2]) * 3600;

        # subscript 7 is yday.

        if ($l[7] == $g[7]) {
                # done
        } elsif ($l[7] == $g[7] + 1) {
                $off += 86400;
        } elsif ($l[7] == $g[7] - 1) {
                $off -= 86400;
        } elsif ($l[7] < $g[7]) {
                # crossed over a year boundry!
                # localtime is beginning of year, gmt is end
                # therefore local is ahead
                $off += 86400;
        } else {
                $off -= 86400;
        }
        return $off;
}

and format it accordingly into the Xml.

Note: See TracTickets for help on using tickets.