Developer's Diary
Daily software development, with Terry Ebdon
BitBucket tabs, Dates, Eclipse & licences

Friday 30th June, 2017

Date bug

There was a bug in my dayNumberSuffix method; see if you can spot it:

def dayNumberSuffix( final Date d ) {
switch ( d.date ) {
case [1,21,31]: "st"; break
case [2,22]: "nd"; break
case [3,23]: "rd"; break
case 4..9: "th"; break
case 24..29: "th"; break
default: 'Huh?'
}
}

Today's page template had a header claiming the date was "30Huh? June". That's not right! So there are two bugs:

  1. It should be the 30th and
  2. it should have thrown an exception:
def dayNumberSuffix( final Date d ) {
switch ( d.date ) {
case [1,21,31]: "st"; break
case [2,22]: "nd"; break
case [3,23]: "rd"; break
case 4..30: "th"; break
default:
project.ant.fail "Unexpected day No. ${d.date}"
}
}

You might find it a bit odd that I'm using Ant to throw the exception. Currently the project logs everything via ant.echo() and ant.fail(). That's because I haven't, yet, incorporated a logging framework. The nice thing with Ant is that I can wire it up to my app's logger, using a listener. So if I add, say, Log4J I don't need to re-write all the existing message code. Plus my log file will then include all the messages that ant itself logs, correctly interleaved and formatted to my standard.

Internationalisation (i18n)

It's time to get a grip on i18n before the project gets too big. This is usually something that, like logging, I'd deal with up front. But this project started as a simple build script, for personal use. Now that it's started to grow, and I've decided to share the code on BitBucket, I need to tidy it up. Java resource bundles are the obvious choice. I can start with properties files and know that I can move the messages into a database, at a later date, with a minor code change. I don't plan to use a DB, but it's good to know that my i18n framework will not cause problems if I do.

Licensing

If I'm making the code public I'll need a licence. I decided on the Apache 2.0 licence. This is a permissive licence that doesn't have the viral infection issues of GPL. I've pasted a header into every code module and updated the Mercurial repository. Eclipse has a useful comment template system, that will add standard templates to new modules, methods etc. So every class file I add will get a standard header, with the current year in the copyright notice and the correct date in the GroovyDoc / JavaDoc @date command.

BitBucket

Viewing the code on BitBucket is a little odd, it's too spaced-out. It's displayed using a tab stop every eight characters, whereas I prefer tabs every four characters. I assumed there'd be a way to configure this, but no. There is a work-around... you have to manually append &ts=4 to the URL, as described in Chris Wareham's comment on BitBucket issue #11111.

Interesting web pages

Installers

Licensing

Open Source Licences

Eclipse

  • Path variables – Eclipse documentation - Archived Release, Eclipse Luna

i18n

Java Resource Bundles

Maven


29th June 👈 Top of page 👉 1st July © 2017 Terry Ebdon

Find me on coding on BitBucket, networking on LinkedIn and hanging out on twitter.