in

Emerald Hand

Emerald Hand, Inc. community home page.

This Blog

  • Home
  • Contact
  • About
  • Directory of Computers/Tech Blogs

Syndication

News

I'm back to blogging

Worm in liquid maze

Design and development of information management tools.

Timestamping in nAnt

I'm using nAnt to automate my projects' build and release. That means from time to time I will write about my experience with automatic building and releasing, and interesting things I find in the process.

Today I had to solve a small problem in a nAnt scripts. I needed to timestamp archive of the release. While nAnt zip task can timestamp the file, the format it uses (MM/DD/YYYY HH:MM:SS) is not suitable for me. I prefer for the project release date to be a part of the version and to follow minor version (i.e. 0.5.20051004). I'm sure there are arguments for and against using such version format, but I like this and I wanted to solve specific problem of generating it.

This is what I came up with:

<property name="date.now" value="${ datetime::now() }"/>
<property name="year.now" value="${ datetime::get-year( date.now )}"/>
<property name="month.now" value="${ datetime::get-month( date.now )}"/>
<property name="month.now" value="0${ month.now }" if="${ int::parse( month.now ) &lt; 10 }"/>
<property name="day.now" value="${ datetime::get-day( date.now )}"/>
<property name="day.now" value="0${ day.now }" if="${ int::parse( day.now ) &lt; 10 }"/>
<property name="timestamp" value="${year.now}${month.now}${day.now}"/>

timestamp property will have current date in YYYYMMDD format. It can be used to timestamp the archive (what I'm using it for), to generate build number, etc.

This is an example of how you could use it to timestamp zip archive:

<zip zipfile="${release.dir}\${project.name}.${timestamp}.zip">
 <fileset basedir="${working-release.dir}">
  <include name="**" />
 </fileset>
</zip>

Some of the properties, like release.dir must be initialized earlier, but I wanted to keep example simple so I omitted all initialization.

If you find a simpler way to generate timestamp let me know. I'd be delighted to hear about it.

Share this post: Email it! | bookmark it! | digg it! | reddit!
Readability Stats: Word Count: 344; Sentence Count: 38; Grade Level: 3.8, more info...
Published Oct 04 2005, 04:39 PM by Ornus
Filed under:

Comments

 

Worm in liquid maze said:

Not long ago I talked about nAnt time stamping. It was an interesting, but unnecessary excersise. If...
November 20, 2005 3:10 PM

Leave a Comment

(required)  
(optional)
(required)  
Add

About Ornus

Lead Sider and Xelog developer. I'm interested in information and how we can better manage it using computers. I'm also into design and understanding how to creating cool, useful, simple things.
Copyright © 2006-2007 EmeraldHand, Inc. All rights reserved.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems