Sign in
  • Blog
  • Archive
  • About
  • Contact

Welcome to rickardnilsson.net

 

rickardnilsson.net is a weblog and the online home of web developer and father of three, Rickard Nilsson... More

Rickard blogs about creating software solutions using ASP.NET and agile practices.

Sites I've visited recently

Rtur.net / ASP.NET Forums / Karstad .NET User Group / JetBrains ReSharper / Scott Hanselman / dnrTV! / MSDN Radio / MIX'08 | Sessions / BlogEngine.Net / YUI Theater

Categories

  • RSS feed for .NET.NET
  • RSS feed for ASP.NET 2.0ASP.NET 2.0
  • RSS feed for BlogEngine.NETBlogEngine.NET
  • RSS feed for C# 2.0C# 2.0
  • RSS feed for C# 3.0C# 3.0
  • RSS feed for CSSCSS
  • RSS feed for Design by ContractDesign by Contract
  • RSS feed for Design PatternsDesign Patterns
  • RSS feed for JavaScriptJavaScript
  • RSS feed for TDDTDD
  • RSS feed for User tipUser tip

Five most recent posts

  • ReSharper User tip #2: Refactor rename namespace
  • Building a Photo Album widget for BlogEngine.NET
  • Applying stylesheets dynamically with jQuery
  • ReSharper User tip: Refactor magical strings to variable
  • Blogging with MS Word 2007

Tag cloud

  • ajax
  • blog
  • blogengine.net
  • c#
  • css
  • dbc
  • design by contract
  • dom
  • douglas crockford
  • foto
  • getweekofyear
  • gregoriancalendar
  • highlight
  • html
  • humble dialog box
  • iso 8601
  • javascript
  • jquery
  • jscript
  • julian bucknall
  • metaweblog api
  • model-view-presenter
  • mvp
  • photo album
  • picasa
  • recent posts
  • refactor
  • refactoring
  • release
  • resharper
  • rhino mocks
  • syntax
  • syntax highlighter
  • tdd
  • test coverage
  • types
  • web service
  • week
  • widget
  • word 2007
  • yahoo
  • yui

Recent comments

  • Syntax Highlighter Release 0.2 Beta (9)
    Rickard wrote: @Tim: Thanks for the positive feedback. To ans… [More]
  • Syntax Highlighter Release 0.2 Beta (9)
    Tim wrote: Do you have this in a working for that does not re… [More]
  • Syntax highlighting in BlogEngine.NET (9)
    darren wrote: thanks for this - got it up and running no problem… [More]
  • Syntax Highlighter Release 0.2 Beta (9)
    Rickard wrote: Line numbers are not supported in the current rele… [More]
  • Syntax Highlighter Release 0.2 Beta (9)
    Jack wrote: How can i show line numbers? [More]
<< Pappaledig! | Driving out a correct implementation of ISO week numbers using TDD: Refactor >>

Abstract: Driving out a correct implementation of week numbers using TDD

Tuesday, 11 March 2008 11:09 by Rickard

The implementation of weeks according to ISO 8601 (used e.g. in Sweden) is faulty in .NET Framework. In particular the GregorianCalendar and CultureInfo classes are faulty when it comes to ISO 8601.

So, how do we know that the implementation of ISO 8601 is faulty using TDD? We come up with a test that fails. By the ISO definition the first week is the week with the year's first Thursday in it. So, we know that e.g. 2003-12-31 is actually week number 01 of 2004 since it is a Wednesday and thus belongs to the first week. The following is a first attempt at a test:

 

Now we get a red bar and we know that the implementation is flawed. However, this is only a single test. If we get a green bar, is the implementation correct? No, of cource not. We need to write more tests to be sure.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   iso 8601, tdd, gregoriancalendar, getweekofyear
Categories:   .NET | C# 2.0 | TDD
Actions:   E-mail | Permalink | Kick it! | DZone it! | del.icio.us | Comments (0) | Comment RSSRSS comment feed

Related posts

Driving out a correct implementation of ISO week numbers using TDD #3 Abstract Refactoring Our task at hand is to get as much coverage as possible when it comes t...Driving out a correct implementation of ISO week numbers using TDD #4 Abstract  Refactoring Test coverage  Proceeding with a solution there is no wa...Driving out a correct implementation of ISO week numbers using TDD: Refactor Abstract So, now we make up another test. Looking at the calendar we see that new years eave 20...
Saving the comment

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



 
Copyright © 2008 rickardnilsson.net