• Index
  •  » Bug reports
  •  » GCUtils problem with recent version of DateTime::Format::Strptime

#1 2018-01-30 07:05:33

van der Decken
Member
Registered: 2018-01-30
Posts: 27

GCUtils problem with recent version of DateTime::Format::Strptime

1. GCstar 1.7.1
2. Linux - Raspbian Stretch and Ubuntu 12.04
3. Date format conversion with newer version of DateTime::Format::Strptime

I noticed something odd while updating a collection that I recently set up.

I had set  the date format in my GCStar preferences to %Y-%m-%d (i.e. year-month-date) on both my Raspbian and Ubuntu systems.

When I edited the collection on the Ubuntu system, everything was fine.

When I did the same thing on Raspbian, I noticed something odd. Whenever I went to edit a date field that had an existing value, the DateTime dialog wouldn't come up with the existing date, but instead used January 1st of the correct year.

Digging into it, I ran gcstar from a terminal and noticed that each time I clicked on the Select button for a date field, the following error appeared:

Code:

Calling pattern() as a writer is deprecated. at /usr/share/perl5/DateTime/Format/Strptime.pm line 888.
    DateTime::Format::Strptime::pattern(DateTime::Format::Strptime=HASH(0x474f658), "%d/%m/%Y") called at /usr/bin/../share/gcstar/lib/GCUtils.pm line 557
    eval {...} called at /usr/bin/../share/gcstar/lib/GCUtils.pm line 552
    GCUtils::DateTimeFormatStrToTime("2018-01-24", "%Y-%m-%d") called at /usr/bin/../share/gcstar/lib/GCGraphicComponents/GCBaseWidgets.pm line 1166
    GCDate::getRawValue(GCDate=HASH(0x414a898)) called at /usr/bin/../share/gcstar/lib/GCGraphicComponents/GCBaseWidgets.pm line 1095
    GCDate::selectValue(GCDate=HASH(0x414a898)) called at /usr/bin/../share/gcstar/lib/GCGraphicComponents/GCBaseWidgets.pm line 1119
    GCDate::__ANON__(Gtk2::Button=HASH(0x414a928)) called at /usr/bin/gcstar line 328
    eval {...} called at /usr/bin/gcstar line 328

I looked at the appropriate bit of source in GCUtils and saw this:

Code:

sub DateTimeFormatStrToTime
{
    my ($date, $format) = @_;
    my $str;
    eval {
        my $dt = new DateTime::Format::Strptime(
                                pattern     => $format,
                                locale      => $ENV{LANG});
        my $dt2 = $dt->parse_datetime($date);
        $dt->pattern('%d/%m/%Y');
        $str = $dt->format_datetime($dt2);
    };
    if ($@)
    {
        return $date;
    }
    return $str;
}

It seemed that  setting the date format in an existing object:

Code:

        $dt->pattern('%d/%m/%Y');

doesn't work with recent versions of Strptime. The Ubuntu system I was running on is a few years old and had an older version of the Strptime module, and it was old enough that that technique still worked.

Discovering this also explained something else that had puzzled me: edits on the Ubuntu system stored dates in the gcs file in dd/mm/yyyy format, while edits on the Raspbain system stored them in yyyy-mm-dd format. Since the format conversion was failing in the newer Strptime, dates were displayed and stored in yyyy-mm-dd format. Which also explained why the date dialog didn't read existing dates correctly on the Raspbian side: they weren't in the correct format.

The following code change in GCUtils seems to fix both the DateTime selector and database date format storage issues:

Code:

sub DateTimeFormatStrToTime
{
    my ($date, $format) = @_;
    my $str;
    eval {
        my $dt = new DateTime::Format::Strptime(
                                pattern     => $format,
                                locale      => $ENV{LANG});
        my $dt2 = $dt->parse_datetime($date);
        # $dt->pattern('%d/%m/%Y');
        # $str = $dt->format_datetime($dt2);
        $str = $dt2->strftime('%d/%m/%Y',$dt2); # this line is added
    };
    if ($@)
    {
        return $date;
    }
    return $str;
}

but my Perl is very, very basic (and my understanding of the internals of GCStar even more so!) so take my 'fix' with a grain or salt. Or even a whole salt lick. I'd be interested to hear if this seems reasonable from someone with more experience with both Perl and GCStar - assuming there's still anyone out there! smile

Offline

 

#2 2018-01-30 12:05:34

kerenoc
Member
Registered: 2016-03-19
Posts: 205
Website

Re: GCUtils problem with recent version of DateTime::Format::Strptime

There're still someone out there! GCstar is still being used and is still receiving contributions to improve it, yours among them.

Thanks for digging into this.

I'm no Perl expert, having learnt it by patching GCstar but I'm ready to integrate your changes into the Gitlab repository I maintain to track the evolutions to the code and the plugins, as the official SVN repository closed last year.

As for GCUtils, I've done some modifications to be able to use the time conversion function not only on the default language of the OS but also in another language (usefull when you use a plugin to a web site in another country). Could you check the changes in the current version of the file and see if there are compatible with your changes and if they are working in your own environment?

Offline

 

#3 2018-01-31 17:50:30

van der Decken
Member
Registered: 2018-01-30
Posts: 27

Re: GCUtils problem with recent version of DateTime::Format::Strptime

I've been using the stock version of 1.7.1 in Debian Stretch, which is a bit dated. It's good to see that it's continued to evolve since then.

I took a quick look at your changes to DateTimeFormatStrToTime and it looks to me as if you've already solved the same problem that I came across. format_datetime and strftime are documented as being synonymous, so I wasn't surprised that replacing my code change with yours worked the same. Thanks!

Offline

 
  • Index
  •  » Bug reports
  •  » GCUtils problem with recent version of DateTime::Format::Strptime



Should you have a problem using GCstar, you can open a bug report or request some support on GCstar forums.