Re: [PATCH (BUGFIX)] gitweb: Fix handling of fractional timezones in parse_date

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2011/3/25 Jakub Narebski <jnareb@xxxxxxxxx>:
> @@ -2921,8 +2921,10 @@ sub parse_date {
> Â Â Â Â$date{'iso-8601'} Â= sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
>
> - Â Â Â $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
> - Â Â Â my $local = $epoch + ((int $1 + ($2/60)) * 3600);
> + Â Â Â my ($tz_sign, $tz_hour, $tz_min) =
> + Â Â Â Â Â Â Â ($tz =~ m/^([+\-])([0-9][0-9])([0-9][0-9])$/);

It's just a matter of personal preference, but I would find this
regexp slightly easier to read:

+               ($tz =~ m/^([+\-])([0-9]{2})([0-9]{2})$/);

> + Â Â Â $tz_sign = ($tz_sign eq '-' ? -1 : +1);
> + Â Â Â my $local = $epoch + $tz_sign*($tz_hour + ($tz_min/60.0))*3600;

If you wanted to avoid floats, you could do something like:

+       my $local = $epoch + $tz_sign * ($tz_hour * 3600 + $tz_min * 60);
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]