Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Code Samples & Tips Share your recent discoveries and ideas with other users.

calendar week (European)

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-03-2007, 02:17 PM
Junior Member
 
Join Date: Apr 2007
Location: Germany
Posts: 36
Default calendar week (European)

I was in need of calculating the calendar week for one of my applications. Sounds easy but finally I spent lots of hours the last days ...
There are lots of algorithms and examples on the net, but most of them don't work perfectly . The treatment of fractured weeks in the beginning and end of a year can be very complicated. But now I have an algorithm that works (as far as I can tell...)

It covers ISO 8601 standard (and the german DIN 1355 standard), so it should be suitable for most European countries. Calculation rules:
  • Week starts with Monday.
  • The first week must have 4 days in January. In other words: the first week must contain the first Thursday of the year. And January 4.
  • Only years starting or ending with Thursday can have a week #53.

Therefore this algorithm will not work for countries where week starts with Sunday (USA?) or the first week bases on January 1 (UK?). More info and links here: http://en.wikipedia.org/wiki/Week

Cheers,
Stefan
Attached Files
File Type: sbp Kalenderwoche.sbp (1.4 KB, 113 views)
__________________
iPAQ 6515, MDA compact
Reply With Quote
  #2 (permalink)  
Old 07-03-2007, 03:07 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 2,344
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

I thought that a year only had 52 weeks...always!

I don't understand how it can have #53...

In Portugal, if the last week of the year as only one or two december days the it's numbered as #1
if not is the #52...
I never came across a 53 week calendar!!!l
__________________
Paulo Gomes - Porto, Portugal - Living/Working in France
Mobile Device: Samsung Galaxy S, Android 2.3.4 CUstom ROM
Laptop: Toshiba NB100-130 (running on Win7Ultimate)

My Posts helped you? Consider Buying me a Porto Glass!
Reply With Quote
  #3 (permalink)  
Old 07-03-2007, 03:27 PM
Junior Member
 
Join Date: Apr 2007
Location: Germany
Posts: 36
Default

Quote:
Originally Posted by Cableguy View Post
I never came across a 53 week calendar!!!l
Cableguy, in Germany the years last always longer ...

Take your PPC, start the calendar, go to the options menue, switch week numbers on. Then go back to the last days of 2004 and switch to week view.

Or have a look here, it's in Portugues.
__________________
iPAQ 6515, MDA compact
Reply With Quote
  #4 (permalink)  
Old 07-03-2007, 03:35 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 2,344
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

Ok So then there should be also 51 weeks years, shouldn't?

For instance, 2003 last week has 3 working days, but is still week 1 of 2004

BtW 2004 1st week is kinda of a halfweek as it only has 2 working days...but that me saying
__________________
Paulo Gomes - Porto, Portugal - Living/Working in France
Mobile Device: Samsung Galaxy S, Android 2.3.4 CUstom ROM
Laptop: Toshiba NB100-130 (running on Win7Ultimate)

My Posts helped you? Consider Buying me a Porto Glass!

Last edited by Cableguy : 07-03-2007 at 03:37 PM.
Reply With Quote
  #5 (permalink)  
Old 07-03-2007, 03:56 PM
specci48's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Germany
Posts: 1,057
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Hi stbi,

I can estimate the work you have put into this code because I had the same problem some time ago. It put me a knot in my brain.

At last, I got to this solution:
Code:
Sub GetWeekNumber(ticks)
    currentThursday = GetThursdayOfWeek(ticks)
    firstThursday = GetThursdayOfWeek(DateAdd(
0, DateYear(currentThursday) - 103))
    
return (currentThursday - firstThursday ) / cTicksPerDay / 7 + 1
End Sub

Sub GetThursdayOfWeek(ticks)
    
select DateDayofWeek(ticks)
        
case "Monday"
            diff = 
3
        
case "Tuesday"
            diff = 
2
        
case "Wednesday"
            diff = 
1
        
case "Thursday"
            diff = 
0
        
case "Friday"
            diff = -
1
        
case "Saturday"
            diff = -
2
        
case "Sunday"
            diff = -
3            
    
end select    
    
return DateAdd(ticks,0,0,diff)
End Sub

specci48
Reply With Quote
  #6 (permalink)  
Old 07-03-2007, 09:16 PM
Junior Member
 
Join Date: Apr 2007
Location: Germany
Posts: 36
Default

Hi specci48,

its amazing, but our codes give exactly the same results this makes me feel good

stbi
__________________
iPAQ 6515, MDA compact
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nth Day of the Month (& numerical Day of the week) LineCutter Code Samples & Tips 4 06-20-2009 09:13 AM
Basic4ppc V6.30 beta will be released next week Erel Announcements 19 09-17-2008 08:36 PM
Calendar Control alfcen Questions (Windows Mobile) 9 02-12-2008 02:28 AM
Calendar event Rioven Questions (Windows Mobile) 7 08-28-2007 07:00 AM
Calendar control BjornF Questions (Windows Mobile) 7 07-05-2007 07:52 AM


All times are GMT. The time now is 10:39 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0