Skip Menu |

This queue is for tickets about the Date-Calc CPAN distribution.

Report information
The Basics
Id: 57169
Status: open
Worked: 10 min
Priority: 0/
Queue: Date-Calc

People
Owner: STBEY [...] cpan.org
Requestors: prote [...] fmi.uni-stuttgart.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Bug: Date-Calc-6.3 errors in parsing calendar profiles
Date: Mon, 3 May 2010 15:39:13 +0200
To: bug-Date-Calc [...] rt.cpan.org
From: Horst Prote <prote [...] fmi.uni-stuttgart.de>
Hello! I'm a Gentoo User and after upgrading from dev-perl/Date-Calc-5.4 to dev-perl/Date-Calc-6.3 I got this error from a perl script using an german calendar profile: Date::Calendar::Year::new(): date '#2/Sun/May' for day 'Muttertag' is invalid Steps to Reproduce: 1. Upgrade to dev-perl/Date-Calc-6.3 2. Run this little perl script: use Date::Calc qw(Decode_Language); use Date::Calendar::Profiles qw($Profiles); use Date::Calendar; $cal = Date::Calendar::Year->new( 2010, $Profiles->{'DE-BW'}, Decode_Language("deutsch") ); Actual Results: Date::Calendar::Year::new(): date '#2/Sun/May' for day 'Muttertag' is invalid at - line 4 Expected Results: No error here This is caused by adding the "$lang" parameter to &_invalid_($item,$name) unless ($dow = Decode_Day_of_Week($dow,$lang)); in line 244 of /usr/lib/perl5/vendor_perl/5.8.8/Date/Calendar/Year.pm but still using english tokens like "Sun" (in german this would be "Son") in the calendar profiles (/usr/lib/perl5/vendor_perl/5.8.8/Date/Calendar/Profiles.pm). So this may affect other languages too. Possible fixes are: - remove the optional "$lang" parameter (as it was in dev-perl/Date-Calc-5.4) - change the english tokens in all affected non-english calendar profiles to their language specific names Horst
On Mon May 03 09:39:30 2010, prote@fmi.uni-stuttgart.de wrote: Show quoted text
> Hello! > > I'm a Gentoo User and after upgrading from dev-perl/Date-Calc-5.4 to > dev-perl/Date-Calc-6.3 I got this error from a perl script using an > german calendar profile: > Date::Calendar::Year::new(): date '#2/Sun/May' for day 'Muttertag' > is invalid > > Steps to Reproduce: > 1. Upgrade to dev-perl/Date-Calc-6.3 > 2. Run this little perl script: > > use Date::Calc qw(Decode_Language); > use Date::Calendar::Profiles qw($Profiles); > use Date::Calendar; > $cal = Date::Calendar::Year->new( 2010, $Profiles->{'DE-BW'}, > Decode_Language("deutsch") ); > > > Actual Results: > Date::Calendar::Year::new(): date '#2/Sun/May' for day 'Muttertag' is > invalid > at - line 4 > > > Expected Results: > No error here > > > > This is caused by adding the "$lang" parameter to > &_invalid_($item,$name) unless ($dow = > Decode_Day_of_Week($dow,$lang)); > in line 244 of /usr/lib/perl5/vendor_perl/5.8.8/Date/Calendar/Year.pm > but still > using english tokens like "Sun" (in german this would be "Son") in the > calendar > profiles (/usr/lib/perl5/vendor_perl/5.8.8/Date/Calendar/Profiles.pm). > So this > may affect other languages too. > > Possible fixes are: > - remove the optional "$lang" parameter (as it was in dev-perl/Date- > Calc-5.4) > - change the english tokens in all affected non-english calendar > profiles to > their language specific names > > > Horst
Since the calendar profile is written in English, adding the optional parameter "Decode_Language('deutsch')" makes no sense. Beware that the country for which a profile is written and the language the dates are written in and the language of the names of the holidays attributed to these dates are all independent from each other! So you have to pick whatever you want, but of course you need to be consistent. The optional "$lang" parameter in Date::Calendar->new() only refers to the language of the dates, NOT to the country and neither to the language of the holiday names. And of course you can write your own profile using German dates, in which case you need to use the "Decode_Language('deutsch')" parameter. So it's not a bug, it's just a question of consistent use.
Subject: Re: [rt.cpan.org #57169] Bug: Date-Calc-6.3 errors in parsing calendar profiles
Date: Fri, 14 May 2010 15:25:22 +0200
To: bug-Date-Calc [...] rt.cpan.org
From: Horst Prote <prote [...] fmi.uni-stuttgart.de>
Steffen Beyer via RT wrote: Show quoted text
> Since the calendar profile is written in English, adding the optional > parameter "Decode_Language('deutsch')" makes no sense. > > ... > > The optional "$lang" parameter in Date::Calendar->new() only refers to > the language of the dates, NOT to the country and neither to the > language of the holiday names.
Oh, I see. So that was me misunderstanding the manual aka reading it too fast, sorry. But I'm still left with one problem: Before the upgrade to Date-Calc-6.3 I used the now deprecated global setting of the language: Language(Decode_Language("deutsch")); which translated the names of days and months into german (especially the day-of-the-week returned by the labels() function. Now I learned from "perldoc Date::Calc" BEWARE that when using the function ""Language()"", the selected language is a global setting, shared by all threads or modules you might be running concurrently, thus possibly causing conflicts between them. In order to avoid these conflicts, you should NEVER use the function ""Language()"", but should ALWAYS pass a language number (as returned by the function ""Decode_Lan- guage()"") to the functions which are language-dependent, which are: "Decode_Month()", "Decode_Day_of_Week()", "Compressed_to_Text()", "Date_to_Text()", "Date_to_Text_Long()", "Calendar()", "Month_to_Text()", "Day_of_Week_to_Text()", "Day_of_Week_Abbreviation()", "Decode_Date_EU()", "Decode_Date_US()", "Decode_Date_EU2()", "Decode_Date_US2()", "Parse_Date()". But labels() is not in this list and so this Code use Date::Calc qw(Decode_Language); use Date::Calendar::Profiles qw($Profiles); use Date::Calendar; $cal = Date::Calendar::Year->new( 2010, $Profiles->{'DE-BW'}); @labels = $cal->labels(2010,5,13); print "@labels","\n"; prints Thursday Christi Himmelfahrt But as I now read the manuals carefully I found the solution: use Date::Calc qw(Decode_Language Decode_Day_of_Week Day_of_Week_to_Text); use Date::Calendar::Profiles qw($Profiles); use Date::Calendar; $cal = Date::Calendar::Year->new( 2010, $Profiles->{'DE-BW'}); @labels = $cal->labels(2010,5,13); $dow = shift(@labels); $dow = Decode_Day_of_Week($dow); $dow = Day_of_Week_to_Text($dow,Decode_Language("deutsch") ); print "$dow @labels\n"; This now prints Donnerstag Christi Himmelfahrt So as you said, it's not a bug, but as this bloats the code a bit: Would it be possible to add an optional LANG argument to labels which translates the returned day-of-the-week?
On Fri May 14 09:25:38 2010, prote@fmi.uni-stuttgart.de wrote: Show quoted text
> But I'm still left with one problem: > Before the upgrade to Date-Calc-6.3 I used the now deprecated global > setting of the language: > Language(Decode_Language("deutsch")); > which translated the names of days and months into german (especially > the day-of-the-week returned by the labels() function. > > Now I learned from "perldoc Date::Calc" > BEWARE that when using the function ""Language()"", the selected > language is a > global setting, shared by all threads or modules you might be > running concurrently, > thus possibly causing conflicts between them. > > In order to avoid these conflicts, you should NEVER use the function > ""Language()"", > but should ALWAYS pass a language number (as returned by the > function ""Decode_Lan- > guage()"") to the functions which are language-dependent, which are: > > "Decode_Month()", "Decode_Day_of_Week()", "Compressed_to_Text()", > "Date_to_Text()", > "Date_to_Text_Long()", "Calendar()", "Month_to_Text()", > "Day_of_Week_to_Text()", > "Day_of_Week_Abbreviation()", "Decode_Date_EU()", > "Decode_Date_US()", > "Decode_Date_EU2()", "Decode_Date_US2()", "Parse_Date()". > But labels() is not in this list and so this Code > use Date::Calc qw(Decode_Language); > use Date::Calendar::Profiles qw($Profiles); > use Date::Calendar; > $cal = Date::Calendar::Year->new( 2010, $Profiles->{'DE-BW'}); > @labels = $cal->labels(2010,5,13); > print "@labels","\n"; > prints > Thursday Christi Himmelfahrt > > But as I now read the manuals carefully I found the solution: > use Date::Calc qw(Decode_Language Decode_Day_of_Week > Day_of_Week_to_Text); > use Date::Calendar::Profiles qw($Profiles); > use Date::Calendar; > $cal = Date::Calendar::Year->new( 2010, $Profiles->{'DE-BW'}); > @labels = $cal->labels(2010,5,13); > $dow = shift(@labels); > $dow = Decode_Day_of_Week($dow); > $dow = Day_of_Week_to_Text($dow,Decode_Language("deutsch") ); > print "$dow @labels\n"; > This now prints > Donnerstag Christi Himmelfahrt > > So as you said, it's not a bug, but as this bloats the code a bit:
Yes, I agree, this solution works but is too clumsy. Show quoted text
> Would it be possible to add an optional LANG argument to labels which > translates the returned day-of-the-week?
I am putting this on the to do list; you are right, I should have added this optional parameter to the "labels" method in the first place; this was an oversight. Sorry for your troubles! Cheers, Steffen
On Sun May 16 09:10:48 2010, STBEY wrote: Show quoted text
> On Fri May 14 09:25:38 2010, prote@fmi.uni-stuttgart.de wrote: >
> > But I'm still left with one problem: > > Before the upgrade to Date-Calc-6.3 I used the now deprecated global > > setting of the language: > > Language(Decode_Language("deutsch")); > > which translated the names of days and months into german (especially > > the day-of-the-week returned by the labels() function. > > > > Now I learned from "perldoc Date::Calc" > > BEWARE that when using the function ""Language()"", the selected > > language is a > > global setting, shared by all threads or modules you might be > > running concurrently, > > thus possibly causing conflicts between them. > > > > In order to avoid these conflicts, you should NEVER use the function > > ""Language()"", > > but should ALWAYS pass a language number (as returned by the > > function ""Decode_Lan- > > guage()"") to the functions which are language-dependent, which are: > > > > "Decode_Month()", "Decode_Day_of_Week()", "Compressed_to_Text()", > > "Date_to_Text()", > > "Date_to_Text_Long()", "Calendar()", "Month_to_Text()", > > "Day_of_Week_to_Text()", > > "Day_of_Week_Abbreviation()", "Decode_Date_EU()", > > "Decode_Date_US()", > > "Decode_Date_EU2()", "Decode_Date_US2()", "Parse_Date()". > > But labels() is not in this list and so this Code > > use Date::Calc qw(Decode_Language); > > use Date::Calendar::Profiles qw($Profiles); > > use Date::Calendar; > > $cal = Date::Calendar::Year->new( 2010, $Profiles->{'DE-BW'}); > > @labels = $cal->labels(2010,5,13); > > print "@labels","\n"; > > prints > > Thursday Christi Himmelfahrt > > > > But as I now read the manuals carefully I found the solution: > > use Date::Calc qw(Decode_Language Decode_Day_of_Week > > Day_of_Week_to_Text); > > use Date::Calendar::Profiles qw($Profiles); > > use Date::Calendar; > > $cal = Date::Calendar::Year->new( 2010, $Profiles->{'DE-BW'}); > > @labels = $cal->labels(2010,5,13); > > $dow = shift(@labels); > > $dow = Decode_Day_of_Week($dow); > > $dow = Day_of_Week_to_Text($dow,Decode_Language("deutsch") ); > > print "$dow @labels\n"; > > This now prints > > Donnerstag Christi Himmelfahrt > > > > So as you said, it's not a bug, but as this bloats the code a bit:
> > Yes, I agree, this solution works but is too clumsy. >
> > Would it be possible to add an optional LANG argument to labels which > > translates the returned day-of-the-week?
> > I am putting this on the to do list; you are right, I should have added > this optional parameter to the "labels" method in the first place; this > was an oversight. > Sorry for your troubles! > > Cheers, > Steffen
I just had a look at the code. Adding an optional "lang" parameter to the "labels" method would require profound changes to several modules. I am afraid that such changes might actually break existing user code out there. I therefore decided not to do this, however desirable it might be. The recommended way of doing what you want to do is the following: use Date::Calc qw(:all); use Date::Calendar::Profiles qw($Profiles); use Date::Calendar; $cal = Date::Calendar::Year->new( 2010, $Profiles->{'DE-BW'}); @date = (2010,5,13); @labels = $cal->labels(@date); print "@labels","\n"; shift(@labels); unshift(@labels,Day_of_Week_to_Text(Day_of_Week(@date),Decode_Language("deutsch"))); print "@labels","\n"; I hope this helps!