Archive for March, 2013

The time that never was

I spent some time tracking down a funny bug yesterday, which suddenly starting clogging our logs with the following error message:

org.joda.time.IllegalFieldValueException: Value 22 for hourOfDay is not supported: Illegal instant due to time zone offset transition

If there are two things I have learned about Joda-Time these past years, it’s that 1) it hardly ever fails and 2) when it does, it’s for a good reason. So I took a look at the code causing the exception and I found this:

max = eventLocalTime.withTime(22, 0, 0, 0);

I see the “22” value but this code has been working flawlessly for weeks, what is suddenly causing it to fail? I fired the debugger, reproduced the problem and inspected the eventLocalTime variable. Something felt a bit unusual about its value:

2013-03-30T22:32:00.000 (America/Godthab)

I won’t claim that I know all the different time zones in existence in North America, but “America/Gothab” is certainly new to me. A quick Google search reveals that this time zone is in Greenland. Alright, so we have users in Greenland, but why would this cause a problem?

Reading this page again, something strikes me:

Next Scheduled DST Transition
DST will begin on Sat 30-Mar-2013 at 10:00:00 P.M. when local clocks are set forward 1 hour

and then everything falls into place.

The variable eventLocalTime is perfectly legitimate but today is March 29th, and adding 22 hours to it puts it into a nonexistent time, which happens whenever a time zone transitions to or from Daylight Savings Time. By adding twenty-two hours to the variable, we were trying to create a date “March 30th, 10pm”, which doesn’t exist because the clock in this time zone skips to 11pm. In the US, this nonexistent time period is usually between 2am and 3am, but for some reason, Greenland does this switch at 10pm.

The fix ended up looking as follows (happy to hear if there is a better solution):

try {
    max = eventLocalTime.withTime(22, 0, 0, 0);
} catch (IllegalFieldValueException e) {
    max = eventLocalTime.withTime(23, 0, 0, 0);
}

I am so happy that Joda will finally become standard with Java 8, and I have to tip my hat to Stephen, again, for his dedication to the terribly hard problem of date management.

If you have any funny bug to share, please go ahead and do so in the comments!

Tags:

A small step for Jebediah, a giant step for Kerbinkind

This is Kerbal Space Program, a sandbox space simulator created by a small team of passionate space programmers. I never really thought that designing rocket ships an aligning orbits could be fun, but I already spent more than thirty hours trying to launch my Kerbals into space (and killing most of them in the process). This turned out to be much more entertaining than I thought.

The game takes place on an imaginary planet called Kerbin. Kerbin looks like the earth and the planetary system it’s located in it has a lot of similarities with our own. As of the current version (0.18, $23, Windows, Mac and Linux), the game allows you to design either rocket ships or airplanes (you can send these to planets as well). Then you launch them and try to follow the plan you decided on.

The screen shot above is Jebediah Kerman, proudly taking his first steps on Mün. It’s the very first successful landing I ever did and it took me about fifty attempts (and countless fiery explosions) to reach this goal. I won’t deny that it was a lot of fun to get there, though, and I learned tons about space travel and ballistics.

The process of mastering the game follows a pretty clear path and while it doesn’t look that there is a big learning distance between your first orbit and your first successful landing, you will soon realize that you need to perfect a lot of intermediary steps in-between. And along the way, you will learn about ship design, the pros and cons of liquid and solid fuel, the compromises of taking a lot of fuel with you, how to launch a ship on a circular orbit, perfecting that orbit, learning how to use and interpret the navball, learning the maneuvers, when and how to perform gravity turns, fuel efficiency, choosing the optimal transfer path between planets, gravity slingshots, controlling your speed to land without exploding, etc…

The game is still in the very early stages and it’s hard not to draw a parallel with the early Minecraft days, where even with so few features, the game has such a strong appeal on imagination that it’s already attracting a very strong and devout following. Take a look at the Kerbal Space Program’s subreddit to get a feel for what people are doing with the game even at such an early stage. I can’t wait to see what it will be like once it reaches 1.0. The developers have managed to take what appears to be a very dry and challenging topic and turn it into a fun and challenging game which remains very approachable. And while you can take a very hard science approach to it, you can also decide to enjoy what it has to offer by simply learning what periapsis and apoapsis are, stopping there and focusing on the flying after that.

As for myself, I still have a lot to do. First, I need to work on fuel efficiency, because even if the Mün landing above was successful, my spaceship is now completely out of fuel (don’t tell Jebediah, he looks so happy). After this, the next step will be to try to land on the more distant planets.

Ad astra!