PowerBASIC Forums
  PowerBASIC for Windows
  Week of Day ? (Page 1)

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone!
This topic is 3 pages long:   1  2  3 
next newest topic | next oldest topic
Author Topic:   Week of Day ?
Matthias Kuhn
Member
posted December 31, 2005 06:10 AM     Click Here to See the Profile for Matthias Kuhn     Edit/Delete Message   Reply w/Quote
Hello,

how to get the week-number of a given ( actual ) day ???

Thanks and regards.

Matthias Kuhn

------------------

IP: Logged

Shawn Anderson
Member
posted December 31, 2005 06:54 AM     Click Here to See the Profile for Shawn Anderson     Edit/Delete Message   Reply w/Quote
I'm not sure what you mean...
Do you want to take a date and figure which week of the year (1-52)
that day falls into?

------------------

I think they should continue the policy of
not giving a Nobel Prize for paneling.

- Jack Handy

IP: Logged

Eric Pearson
Member
posted December 31, 2005 07:01 AM     Click Here to See the Profile for Eric Pearson     Edit/Delete Message   Reply w/Quote
Matthias --

There are several different methods for determining the week number. Does week 1 start on January 1, or is it the first full week in January, or does it start in December if there are 1-6 days left over from the previous year...?

Search these forums and you will find a number of discussions about this topic, and lots of code.

-- Eric

------------------
Perfect Sync Development Tools
Perfect Sync Web Site
Contact Us: support@perfectsync.com

IP: Logged

Ron Dunn
Member
posted December 31, 2005 07:01 AM     Click Here to See the Profile for Ron Dunn     Edit/Delete Message   Reply w/Quote
The following query gives HUNDREDS of examples:
http://www.google.com.au/search?sourceid=navclient&ie=UTF-8&rls=GGLG,GGLG:2005-51,GGLG:en&q=algorithm+date+to+week+number

------------------

IP: Logged

Egbert Zijlema
Member
posted December 31, 2005 08:08 AM     Click Here to See the Profile for Egbert Zijlema     Edit/Delete Message   Reply w/Quote
Matthias,

Windows supports 2 or 3 methods to calculate week numbers. One method is based on a calendar that shows Sundays as the first day of the week (as used in the USA).
However, according to the rules set by the International Organisation for Standardization (ISO) this is wrong. Monday is the first day of the week.

Having said this: the week wherein the first Thursday of the year falls (or: the week that counts at least 4 days) is week 1. For instance, in 2006 January 1 is
part of week 52 of 2005. The week starting with January 2 is week 1 in 2006.

If you drop me an e-mail, I will send you a routine.

------------------
Egbert Zijlema, journalist and programmer (egbert at egbertzijlema dot nl)
http://www.egbertzijlema.nl/programming.html
*** Opinions expressed here are not necessarily untrue ***

[This message has been edited by Egbert Zijlema (edited January 01, 2006).]

IP: Logged

Egbert Zijlema
Member
posted January 01, 2006 08:42 AM     Click Here to See the Profile for Egbert Zijlema     Edit/Delete Message   Reply w/Quote
Matthias,

No need to send me an e-mail. I posted the code already, but it was so long ago that I did not remember.
Download it here: http://www.powerbasic.com/support/forums/Forum7/HTML/001585.html

------------------
Egbert Zijlema, journalist and programmer (egbert at egbertzijlema dot nl)
http://www.egbertzijlema.nl/programming.html
*** Opinions expressed here are not necessarily untrue ***

IP: Logged

Michael Mattias
Member
posted January 01, 2006 10:21 AM     Click Here to See the Profile for Michael Mattias     Edit/Delete Message   Reply w/Quote
>Windows supports 2 or 3 methods to calculate week numbers

APIs? I can't find any functions in SDK which do anything with 'week numbers.'


IP: Logged

Peter Jinks
Member
posted January 01, 2006 01:26 PM     Click Here to See the Profile for Peter Jinks     Edit/Delete Message   Reply w/Quote
quote:

APIs? I can't find any functions in SDK which do anything with 'week numbers.'

Perhaps you're not looking hard enough. Try VarFormat, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/automat/html/2e1b4fd1-a86b-4933-8934-5d725168a2cd.asp

Regards,

Pete.

[This message has been edited by Peter Jinks (edited January 01, 2006).]

IP: Logged

Egbert Zijlema
Member
posted January 01, 2006 01:52 PM     Click Here to See the Profile for Egbert Zijlema     Edit/Delete Message   Reply w/Quote
I'm sorry. Of course there is no support in that way.
It is a rather long time ago when I was oocupied with this stuff, but I certainly do remember the 3 possibilities:

  1. week 1 is simply the week wherein Jan. 1 falls
  2. week 1 is the first full week of January
  3. week 1 is the week that contains the first Thursday (and Monday is the first day of the week) - ISO-rule


As a European I stick to the ISO-rules which are mandatory in all the member states of the European Union.

------------------
Egbert Zijlema, journalist and programmer (egbert at egbertzijlema dot nl)
http://www.egbertzijlema.nl/programming.html
*** Opinions expressed here are not necessarily untrue ***

IP: Logged

Egbert Zijlema
Member
posted January 03, 2006 09:56 AM     Click Here to See the Profile for Egbert Zijlema     Edit/Delete Message   Reply w/Quote
It is, indeed, a long time ago, folks.
I once started a project dealing with this issue, but due to several causes I never finished it.
And yes, Windows does support week numbers in a way.
You should call GetLocaleInfo, passing %LOCALE_IFIRSTWEEKOFYEAR as LCType, to retrieve a value from 0 - 2.
This is what those values mean:

  • 0: Week containing January 1 is the first week of the year.
  • 1: First full week following January 1 is the first week.
  • 2: First week containing at least 4 days is the first week.

The latter is very close to ISO-rule 8601. However, according to ISO a second rule applies: Monday is the
first day of the week. Maybe this is always the case by default? I mean: maybe %LOCALE_IFIRSTWEEKOFYEAR
returns a value of 2 only when at the same time %LOCALE_IFIRSTDAYOFWEEK returns 0 (= Monday)?
I don't know, because I did not find information from Microsoft available.

Here's some code. It is rather surprising, because several member states of the European
Union do not strictly follow ISO-rules. Although Monday is considered to be the first day
of the week, those countries consider the week wherein January 1 falls to be week number 1. Anyhow, this
is the case on my box, running XP Home and SP1. I do not know if the programmers from Redmond did a good
job here. Can somebody, living in those countries (Spain, France, Belgium) confirm this?

Another surprise is that I did not find countries where the first full week is week number 1.
Surprise #3: I did not find Tuesday thru Saturday as first day of the week.

NOTE: The forthcoming days I will add a working week number routine to my well known Gregorian functions.


%LOCALE_IFIRSTDAYOFWEEK = &H0000100C ' first day of week specifier
%LOCALE_IFIRSTWEEKOFYEAR = &H0000100D ' first week of year specifier
DECLARE FUNCTION GetLocaleInfo LIB "KERNEL32.DLL" ALIAS "GetLocaleInfoA" (BYVAL Locale AS LONG, BYVAL LCType AS LONG, lpLCData AS ASCIIZ, BYVAL cchData AS LONG) AS LONG

%IDM_GERMAN = 1031
%IDM_ENGLISH_US = 1033
%IDM_SPANISH = 1034
%IDM_FRENCH = 1036
%IDM_ITALIAN = 1040
%IDM_DUTCH = 1043
%IDM_SWEDISH = 1053
%IDM_GERMAN_SWISS = 2055
%IDM_ENGLISH_UK = 2057
%IDM_FLEMISH = 2067
%IDM_GERMAN_AUSTR = 3079

FUNCTION GetFirstWeek(lLocale AS LONG) AS STRING
LOCAL szWeek AS ASCIIZ * 2

GetlocaleInfo lLocale, %LOCALE_IFIRSTWEEKOFYEAR, szWeek, SIZEOF(szWeek)
SELECT CASE AS LONG VAL(szWeek)
CASE 0
FUNCTION = "Week 1: Week containing January 1."
CASE 1
FUNCTION = "Week 1: First full week."
CASE 2
FUNCTION = "Week 1: Week containing at least 4 days."
END SELECT
END FUNCTION

FUNCTION GetFirstWeekDay(lLocale AS LONG) AS STRING
LOCAL szDay AS ASCIIZ * 2, sDayName AS STRING

GetlocaleInfo lLocale, %LOCALE_IFIRSTDAYOFWEEK, szDay, SIZEOF(szDay)
SELECT CASE AS LONG VAL(szDay)
CASE 0 : sDayName = "Monday"
CASE 1 : sDayName = "Tuesday"
CASE 2 : sDayName = "Wednesday"
CASE 3 : sDayName = "Thursday"
CASE 4 : sDayName = "Friday"
CASE 5 : sDayName = "Saturday"
CASE 6 : sDayName = "Sunday"
END SELECT
FUNCTION = "First day of the week: " & sDayName
END FUNCTION

FUNCTION PBMain() AS LONG
LOCAL sText AS STRING

sText = "BELGIUM:" & $CRLF & _
GetFirstWeek(%IDM_FLEMISH) & $CRLF & GetFirstWeekDay(%IDM_FLEMISH) & REPEAT$(2, $CRLF)
sText = sText & "FRANCE:" & $CRLF & _
GetFirstWeek(%IDM_FRENCH) & $CRLF & GetFirstWeekDay(%IDM_FRENCH) & REPEAT$(2, $CRLF)
sText = sText & "GERMANY:" & $CRLF & _
GetFirstWeek(%IDM_GERMAN) & $CRLF & GetFirstWeekDay(%IDM_GERMAN) & REPEAT$(2, $CRLF)
sText = sText & "ITALY:" & $CRLF & _
GetFirstWeek(%IDM_ITALIAN) & $CRLF & GetFirstWeekDay(%IDM_ITALIAN) & REPEAT$(2, $CRLF)
sText = sText & "(THE) NETHERLANDS:" & $CRLF & _
GetFirstWeek(%IDM_DUTCH) & $CRLF & GetFirstWeekDay(%IDM_DUTCH) & REPEAT$(2, $CRLF)
sText = sText & "SPAIN:" & $CRLF & _
GetFirstWeek(%IDM_SPANISH) & $CRLF & GetFirstWeekDay(%IDM_SPANISH) & REPEAT$(2, $CRLF)
sText = sText & "SWEDEN:" & $CRLF & _
GetFirstWeek(%IDM_SWEDISH) & $CRLF & GetFirstWeekDay(%IDM_SWEDISH) & REPEAT$(2, $CRLF)
sText = sText & "SWITZERLAND:" & $CRLF & _
GetFirstWeek(%IDM_GERMAN_SWISS) & $CRLF & GetFirstWeekDay(%IDM_GERMAN_SWISS) & REPEAT$(2, $CRLF)
sText = sText & "UK:" & $CRLF & _
GetFirstWeek(%IDM_ENGLISH_UK) & $CRLF & GetFirstWeekDay(%IDM_ENGLISH_UK) & REPEAT$(2, $CRLF)
sText = sText & "USA:" & $CRLF & _
GetFirstWeek(%IDM_ENGLISH_US) & $CRLF & GetFirstWeekDay(%IDM_ENGLISH_US)

MSGBOX sText, 64, "Week number checks"
END FUNCTION

------------------
Egbert Zijlema, journalist and programmer (egbert at egbertzijlema dot nl)
http://www.egbertzijlema.nl/programming.html
*** Opinions expressed here are not necessarily untrue ***

[This message has been edited by Egbert Zijlema (edited January 03, 2006).]

IP: Logged

Egbert Zijlema
Member
posted January 03, 2006 03:21 PM     Click Here to See the Profile for Egbert Zijlema     Edit/Delete Message   Reply w/Quote
Windows does support week numbers. See: previous message in this thread.

------------------
Egbert Zijlema, journalist and programmer (egbert at egbertzijlema dot nl)
http://www.egbertzijlema.nl/programming.html
*** Opinions expressed here are not necessarily untrue ***

IP: Logged

Michael Mattias
Member
posted January 03, 2006 05:21 PM     Click Here to See the Profile for Michael Mattias     Edit/Delete Message   Reply w/Quote
GetLocaleInfo==> perfect to get week number based on my locale setting.

But... is there a way to set that? On control panel, there is no place under 'regional settings' (which is where Windows help sent me) for 'week method' or 'first day of week'.

Or is this something supplied with the O/S and you live with it, adjusting that 'week number' if necessary based on the factory-installed options?

IP: Logged

Egbert Zijlema
Member
posted January 03, 2006 06:40 PM     Click Here to See the Profile for Egbert Zijlema     Edit/Delete Message   Reply w/Quote
It's in the registry. See: HKEY_CURRENT_USER\Control Panel\International

------------------
Egbert Zijlema, journalist and programmer (egbert at egbertzijlema dot nl)
http://www.egbertzijlema.nl/programming.html
*** Opinions expressed here are not necessarily untrue ***

[This message has been edited by Egbert Zijlema (edited January 03, 2006).]

IP: Logged

Matthias Kuhn
Member
posted January 03, 2006 07:05 PM     Click Here to See the Profile for Matthias Kuhn     Edit/Delete Message   Reply w/Quote
Thanks all for response !

Egbert I´ll take Your old code from the October 20, 2002, because
I´m in Germany and the Code works.

I`think there are a Windows-Solution too - but I´m new with
PB8 Win and it is quicker to use a longer code and spend less
time to think of API Commands:

found in CommCrtl.inc
---------------------
%MCHT_CALENDARWEEKNUM = %MCHT_CALENDAR OR &H0003

%MCS_WEEKNUMBERS = &H0004

Thanks for help an using Your Code.

Best Regards

Matthias Kuhn

------------------

IP: Logged

Paul Dixon
Member
posted January 03, 2006 07:19 PM     Click Here to See the Profile for Paul Dixon     Edit/Delete Message   Reply w/Quote
Mattias,
<<I´m new with PB8 Win and it is quicker to use a longer code and spend less time to think of API Commands:>>

I think this is a general problem with Windows programming. People spend way too much time trying to find/understand/shoe horn into their application a complicated Windows way of doing things which takes far longer in many cases than just writing the code from scratch.
And, in the latter case, you know no one is going to mess it up in a later version of the OS.

Paul.

------------------

IP: Logged


This topic is 3 pages long:   1  2  3 

All times are EasternTime (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | PowerBASIC BASIC Compilers

Copyright © 1999-2007 PowerBASIC, Inc. All Rights Reserved.


Ultimate Bulletin Board 5.45c