Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Code Samples & Tips
Home Register FAQ Members List 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, 03:17 PM
Junior Member
 
Join Date: Apr 2007
Location: Germany
Posts: 34
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, 63 views)
__________________
iPAQ 6515, MDA compact
Reply With Quote
  #2 (permalink)  
Old 07-03-2007, 04:07 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 1,319
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

PC: Dual-Core 1,8Ghz, 2GB RAM, 80GB HD
PPC: Qtek9000, 1GB SD

DLL Version Listing
Reply With Quote
  #3 (permalink)  
Old 07-03-2007, 04:27 PM
Junior Member
 
Join Date: Apr 2007
Location: Germany
Posts: 34
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, 04:35 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 1,319
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

PC: Dual-Core 1,8Ghz, 2GB RAM, 80GB HD
PPC: Qtek9000, 1GB SD

DLL Version Listing

Last edited by Cableguy : 07-03-2007 at 04:37 PM.
Reply With Quote
  #5 (permalink)  
Old 07-03-2007, 04:56 PM
specci48's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Germany
Posts: 638
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) - 1, 0, 3))
	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, 10:16 PM
Junior Member
 
Join Date: Apr 2007
Location: Germany
Posts: 34
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 On
Pingbacks are On
Refbacks are On

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


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


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0