tags:

views:

43

answers:

3

Lately I've been wondering if there were an alternative to a revision number (incremented int). I like to create at revision tag (or identifier if you like) from date/time (and later to covert the tag back to a date time object).

Preferably the revision is as small as possible. CouchDB is using a format like this for revision: 765B7D1C - but I'm uncertain how they made this and if it's even a time stamp.

Any suggestions...?

+1  A: 

You could use something like this:

DateTime.Now.Subtract(new DateTime(2000, 1, 1)).Days

This returns the number of days since 2000-01-01 (as of today, this would be 3566).

This is similar to what is used in .NET if you specify the assembly version (in AssemblyInfo.cs) as "1.0.*". Of course you could also use another start date, such as the start of your project.

M4N
Well lets say there is two updates in one day... then it wouldn't work.
Tim
Wouldn't this just mean that the revId <--> revision mapping isn't necessarily bijective? And, technically speaking, this is just a monotonically increasing integer (something OP said they wanted an alternative to) which happens to correspond to time since an arbitrary date.
Andrew Song
The idea is good though. ((long)DateTime.Now.Subtract(new DateTime(2000, 1, 1)).TotalMilliseconds).ToString("X") would give a result like 47C0FAF85B - better, but still needs improving
Tim
A: 

I recently went through the same thought process. I couldn't find a good way to fit it into the signed int that your allowed. Instead I went with Maj.{Year-2000}.{MMdd}.{svn revision}. You could still try and cram the date... here is the issue:

1 year = 365 days = 8760 hours = 525600 minutes. As you can see given a max of 32k the best you can do for the current year is hours. That can record the next 3.5 years worth, so you could do:

int revision = (int) (DateTime.Now - new DateTime(2009, 1, 1)).TotalHours;

... and this will then blow up around Aug, 2012. Or if you use days you be able to store apx 88 years, so you could go with Martin's suggestion safely.

csharptest.net
A: 

Take a look at VSVersion Manager which is a set of macros for setting version numbers in AssemblyInfo based on date.

The macro is fired on each build.

You can set up a rules for setting revision fields to any of the date elements (month, day, year in different formats), have them increment by one or leave them untouched.

The site includes detailed instructions for installing the macros.

Jay Riggs