Recent

Author Topic: [SOLVED]TCalendar : False number of the week with windows  (Read 12049 times)

gjpneac

  • New Member
  • *
  • Posts: 16
[SOLVED]TCalendar : False number of the week with windows
« on: July 17, 2012, 05:14:38 pm »
Hello,

Today's date is Tuesday, July 17, 2012... and Today's Week number is 29... and my TCalendar indicates 30. Look at the attachment please.

Regards.
« Last Edit: July 17, 2012, 09:24:43 pm by gjpneac »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: TCalendar : False number of the week ?
« Reply #1 on: July 17, 2012, 05:19:28 pm »
Depends on your definition of week number. There are multiple definitions across the world.

Perhaps you can influence the calculated number with an additional parameter or setting some property.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

gjpneac

  • New Member
  • *
  • Posts: 16
Re: TCalendar : False number of the week ?
« Reply #2 on: July 17, 2012, 05:35:14 pm »
Ah... on lazarus planet perhaps... but usually, please, look at http://www.calendardate.com/todays.htm, http://www.epochconverter.com/epoch/weeknumbers.php, http://whatweekisit.com/...
Regards.


« Last Edit: July 17, 2012, 05:39:12 pm by gjpneac »

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: TCalendar : False number of the week ?
« Reply #3 on: July 17, 2012, 05:47:51 pm »
Yes, I would have expected Lazarus to be using  ISO-8601, but it appears not.

Ironically WeekOf returns the correct ISO-8601 week number.

gjpneac

  • New Member
  • *
  • Posts: 16
Re: TCalendar : False number of the week ?
« Reply #4 on: July 17, 2012, 05:52:09 pm »
Yes, I don't understand : WeekOfTheYear(aCalendar.DateTime) returns 29 on the TCalendar indicates 30;   
So  I have a problem of coherence.  :o. You see ?

In Win32WSCalendar :    MCHT_CALENDARWEEKNUM : Result := cpWeekNumber;

With Linux (Ubuntu), the number of the week is correct. But the display is bad (look at attachment).
Regards.     
« Last Edit: July 17, 2012, 06:51:27 pm by gjpneac »

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: TCalendar : False number of the week ?
« Reply #5 on: July 17, 2012, 06:38:49 pm »
Bit of digging, it's actually a windows thing.

Try changing this registry value to 2..

HKEY_CURRENT_USER\Control Panel\International\iFirstWeekOfYear

gjpneac

  • New Member
  • *
  • Posts: 16
Re: TCalendar : False number of the week ?
« Reply #6 on: July 17, 2012, 07:00:25 pm »
Yes. It works : I have changed this registry value to 1.

By default, it's 0. (Windows 7 Edition Intégrale - Service pack 1 - 32 bits)

It is the same value on my other computers with 7 or XP. The iFirstday of the registry is also 0 and the display of the Tcalendar's days are correct. It is thus a very temporary solution. I suppose that it is necessary to indicate the problem on the bug tracker ?

Thanks. Regards.
« Last Edit: July 17, 2012, 07:12:41 pm by gjpneac »

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: TCalendar : False number of the week ?
« Reply #7 on: July 17, 2012, 08:06:36 pm »
Quote
I suppose that it is necessary to indicate the problem on the bug tracker ?

Well, not in the Lazarus bug tracker, as it's not a Lazarus bug.

The Calendar component is just a wrapper for the common controls Calendar component that Microsoft made.  And basically Microsoft gets these settings from it's locale, that was basically the registry entry I showed.

Ideally the inconsistency is not ideal, from what I can tell Microsoft gives no option for changing this from the component level, only the registry.  To be consistent Lazarus would need to examine this registry too, and WeekOf/WeekOfTheYear would need modifying too.  Not sure what the Dev's would make of this though.

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: TCalendar : False number of the week ?
« Reply #8 on: July 17, 2012, 08:12:27 pm »
Also any reason you set to 1, instead of 2 like I mentioned?.
These are the values for iFirstWeekOfYear

- 0 Week containing 1/1 is the first week of that year.
- 1 First full week following 1/1 is the first week of that year.
- 2 First week containing at least four days is the first week of that year.

From what I can gather option 2 is the ISO-8601 variant.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: TCalendar : False number of the week ?
« Reply #9 on: July 17, 2012, 08:50:18 pm »
Quote
from what I can tell Microsoft gives no option for changing this from the component level, only the registry
Code: [Select]
uses ...,windows;

SetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_IFIRSTWEEKOFYEAR, '2'); 
Note that the 3rd parameter is a string, just as the registry value.

gjpneac

  • New Member
  • *
  • Posts: 16
Re: TCalendar : False number of the week ?
« Reply #10 on: July 17, 2012, 09:23:58 pm »
@Ludob : Perfect. Thank you very much to all of you.
Regards.
« Last Edit: July 17, 2012, 09:29:06 pm by gjpneac »

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: [SOLVED]TCalendar : False number of the week with windows
« Reply #11 on: July 17, 2012, 10:01:44 pm »
Please note this is basically doing the same as modifying the registry.

http://msdn.microsoft.com/en-us/library/windows/desktop/dd374049(v=vs.85).aspx

Quote
Caution  Because this function modifies values for all application

Remarks
This function writes to the registry, where it sets values that are associated with a particular user instead of a particular application.

So like I said, from what I can gather there is no option to modify at the component level.   A warning for users of your application might be an idea, for a system change like this.  eg. "Please note your locale for Week Number  is not set to ISO-8601, would you like it changing to ISO-8601", or something like that.

Quote
LOCALE_SYSTEM_DEFAULT

Would this also be better as LOCALE_USER_DEFAULT?
What would have been nice is LOCALE_PROCESS_DEFAULT :)
« Last Edit: July 17, 2012, 10:16:58 pm by KpjComp »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: TCalendar : False number of the week ?
« Reply #12 on: July 17, 2012, 11:10:02 pm »
Ah... on lazarus planet perhaps...
Quote from: gjpneac link=topic=17573
@Ludob : Perfect. Thank you very much to all of you.
Regards.
;)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

JD

  • Hero Member
  • *****
  • Posts: 1848
Re: TCalendar : False number of the week ?
« Reply #13 on: July 17, 2012, 11:44:47 pm »
Quote
from what I can tell Microsoft gives no option for changing this from the component level, only the registry
Code: [Select]
uses ...,windows;

SetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_IFIRSTWEEKOFYEAR, '2'); 
Note that the 3rd parameter is a string, just as the registry value.

Thanks a lot for the tip. I confirm that it works.  :D
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

 

TinyPortal © 2005-2018