.NET Does not Support Leap Seconds

In my seemingly never ending quest to understand how accurately represent dates and times worldwide, I found out that .NET does not support leap seconds.  For those of you unfamiliar with the concept, “The Wikipedia” has a nice introduction.  Basically UTC uses an atomic clock to keep time (read: accurate) and the rest of us use a spinning ball circling another spinning ball to keep time (read: inaccurate).  The net result is we need to add or subtract a second here and there to keep things in line.  This is in addition to that whole day we throw into the mix every four years or so.

Anywhoo, this forum question raises some valid questions, so I did a quick check on my own and the following code does indeed throw an exception when it shouldn’t:

DateTime foo = new DateTime(2005, 12, 31, 23, 59, 60, DateTimeKind.Utc);

The MSDN documentation is mum on the issue, so I think it’s safe to say that this wasn’t a consideration.  It even specifically says that the second value will be on the range [0, 59].  This is just something to be aware of if you’re implementing a protocol that does support leap seconds, such as the iCalendar specification.

As an aside, this site is a good reference for all sorts of mistakes programmers make when working with dates & times.

Add comment April 13th, 2008

Visual Studio 2003 Web Projects Not Loading?

Took me a while to find a solution to this problem.

I checked out a project from Visual Source Safe (using the VS2005 client) to my local drive and tried to open the solution.  The solution contained several projects, two of which were web projects.  I had previously checked out the project to this computer, and IIS had virtual directories mapped to the old location.  I changed the target of the virtual directories to my newly checked out location and figured that everything would be OK.  No dice.

The problem was that Visual Studio claimed it couldn’t find the project files.  The virtual directories were mapped correctly.  Directory permissions were OK.  Crazy.

After searching the web for a while I was able to locate something that works.  To resolve the problem do the following:

  1. Check out the project from source control (get latest).
  2. Map virtual directories to correct locations.
  3. Delete the project files for the web projects on the local computer (the .csproj and the .vspscc files for a C# web project).
  4. Delete the solution preferences files (the .suo file).  This only exists if you have previously tried to open the project locally.
  5. Launch Visual Studio and open the project.

Not exactly the most straight forward workaround.  But is seems to work.  Thankfully things seem a bit better in Visual Studio 2005.If I run into this problem again, I’ll record more specific error messages so Google will help locate the solution.  I’ll also try to get some screenshots.

Add comment April 3rd, 2008

Restrictions on Date queries with WebDAV SQL for Exchange

Turns out that you can’t query Exchange appointments for arbitrary date ranges.  According to Patrick at Microsoft (appropriate since it’s St. Patrick’s day), you are limited to querying to a 2 year range if you are searching for on both start and end date. For example, the below query is not legal:

SELECT
  "DAV:contentclass", "urn:schemas:calendar:dtstart",
  "urn:schemas:calendar:dtend",
  "http://schemas.microsoft.com/mapi/subject"
FROM
  "https://mail.example.com/exchange/somemailbox/Calendar"
WHERE
  "DAV:contentclass" = 'urn:content-classes:appointment'
  AND
  "urn:schemas:calendar:dtend" >=  CAST(\"2008-03-18T20:03:21.312Z\" as 'dateTime')
  AND
  "urn:schemas:calendar:dtend" <=  CAST(\"2028-03-18T20:03:21.312Z\" as 'dateTime') "

This doesn’t mean that queries can’t return more than two years worth of results, you just can used date ranges of more than two years. The resulting error is a (422) Unprocessable Entity. Other causes for this error are attempting to search on unsearchable fields.

2 comments March 18th, 2008

.NET Default Numeric String Formatting not Reflexive?

Does the following look like it should throw an exception?

Double.Parse(Double.MaxValue.ToString())

I didn’t think so either, but it turns out I was wrong. Double.MaxValue.ToString() yields 1.79769313486232E+308 when the actual maximum value of a Double is 1.7976931348623157E+308. Ok, we’ll shave off a few digits of precision with the default formatting and round up. Sure…Turns out you need to use the “roundtrip” option…sigh. Thanks to this reference.

Double.Parse(Double.MaxValue.ToString("R"))

1 comment January 28th, 2008

Frequently Asked .NET 2.0 Questions

These questions/answers can be great when prepping for a .NET developer interview, or they can be a fun way to test your understanding of the platform.  For the ones you don’t know, questions like these can help you find areas in which you should do some reading to help round out your understanding.

Add comment November 18th, 2007

Structuring your database update scripts

I’m currently working on a project that will serve as the back-end for my adult hockey teams website (more on that to come). I’m also using this project as a test bed for some ideas I’d like to try at work for upcoming development.

One of the big problems we face with our current iteration of our product is that we need to manage the structure of the database. We have a .NET app that has a database back-end powering some web services and a web based interface to the product. The problem is we have many customers (well, I guess that’s not a problem) and they tend to be running different versions of the product, and hence different version of the database. As part of customization services we offer, we may need to make minor alterations to the database structure that later get rolled into the next major product release.

Back to the hockey info manager. I’ve been researching best practices on how to structure your development environment to help manage all these challenges, and I’ve been basing a lot of what I’m doing on Jean-Paul S. Boodhoo’s work, as posted previously. For these database problems, I’m working with this post in particular.

Specifically, Jean-Paul advocates splitting database creation scripts into multiple templated files to handle creating the various aspects of the database. I’ve generalized this a bit more so that there are multiple phases to the database, the initial phase and the update phase.

The database scripts are setup with the following naming convention:

YYYYY.##.ZZZZZ.sql.template

Where each of the sections means the following:

  • YYYYY - The phase of the database creation this script applies to
  • ## - Within the phase, the order in which the script should be executed
  • ZZZZZ - A human friendly description of what the script addresses

The database creation scripts are divided up into three phases: Initial,
Update, and Test.

The Initial phase create the database fresh for the current major release. These
scripts deal with dropping the existing database if it exists, and creating
everything from scratch.

The Update phase moves the database from it’s initial phase to the most current
configuration. Once the product has been released for use, the Initial phase
scripts should no longer be updated, but rather the Update phase scripts should
contain all changes to the database as part of patches, hotfixes, etc.
Furthermore, scripts in the updates phase should assume that data already
exists within the system and nothing should be broken by running the upgrade
scripts. This includes customers who may have previously had their database
updated (inidicating the script is being run on a database that has been
partially updated). By combining (in order) the scripts in the update phase,
a master database update script can be generated that will take the database
from any state on or after the initial state to the most current phase.

When the product is being prepared for a major version release, a master upgrade
package is created that combines all the updates from the previous version.
This script is kept separately as part of a migration package, and all the
changes in the updates are incorporated into the initial creation scripts. At
this point the update scripts are wiped clean and the process begins again.

The Test phase does not include any changes to the structure of the database
but rather only adds data to the database that can be used in testing.

Below is the list of files currently in use in the project:

Initial.00.Database.sql.template
Initial.01.Views.sql.template
Initial.02.StoredProcedures.sql.template
Initial.03.Security.sql.template
Initial.04.Data.sql.template
Update.00.Database.sql.template
Update.01.Views.sql.template
Update.02.StoredProcedures.sql.template
Update.03.Security.sql.template
Update.04.Data.sql.template
Test.00.Data.sql.template

Obviously, I have yet to test this structure in practice, but I’ll keep the blog up to date with how well this structure ends up working.

Add comment October 27th, 2007

NAnt and Project Directory Structure

Jean-Paul S. Boodhoo has some great articles regarding getting started with NAnt and how to structure your projects for maintainability and testability.  Working in a .NET shop that’s using Source Safe, I’ve realized how you really need to pay attention to these things before the file structure of your code gets out of control and things get overlooked.  Personally, I’ve sued ant before when I was doing work in Java, so this isn’t a big switch, but it’s still great to have a reference on best practices.

Add comment October 22nd, 2007

F#

There has been a lot of buzz in the .NET community regarding F# and it’s becoming a first class language in .NET. Personally, I’m thrilled as F# is rooted in ML and OCaml. As soon as I get past my current project, I plan to spend some time taking F# for a test run.

Add comment October 22nd, 2007

Uncommon C# Keywords

Everyone knows the basic C# keywords, but some are more obscure. This article dives into some useful C# keywords that you may have yet to encounter.

kick it on DotNetKicks.com

Add comment October 10th, 2007

Terrible Programmer

Here is a nice little bit of satire that drives home the point that you can only be a good programmer when you acknowledge that you’re going to be constantly making mistakes, and you’re virtually paranoid about trying to find them.  Wisdom to live by.

Add comment October 8th, 2007

Next Posts Previous Posts


Categories

Links

Feeds