my2cents

28. April, 2008

IE: Could not get the visibility property. Invalid argument.

Filed under: Web Authoring — frightanic @ 22:55

This blog now resides at http://www.frightanic.com/. It will be discontinued here…

Microsoft’s Internet Explorer never fails to amaze me – coding JavaScript and CSS for the IE is quite a challenge. The other day I tried to show/hide a table based on the value of a dropdown box.

function hideUnhideDateFields() {
	var tarifScheme = document.getElementById("dropdownTarifscheme");
	var dateTable = document.getElementById("dateTable");
	if (tarifScheme && tarifScheme.value == "") {
		dateTable.style.visibility = "collapse";
	} else {
		dateTable.style.visibility = "visible";
	}
}

While this works flawlessly with browsers, the script crashes in IE: it complains about “Could not get the visibility property. Invalid argument.” Hey IE, talk to me, what is your problem?
I couldn’t get behind it and switched stratey, therefore.

function hideUnhideDateFields() {
	var tarifScheme = document.getElementById("dropdownTarifscheme");
	var dateTable = document.getElementById("dateTable");
	if (tarifScheme && tarifScheme.value == "") {
		dateTable.style.display = "none";
	} else {
		dateTable.style.display = "";
	}
}
Advertisements

15. April, 2008

Java SimpleDateFormat and 4-digit year vs. 2-digit year

Filed under: Java,Software Development — frightanic @ 23:35

This blog now resides at http://www.frightanic.com/. It will be discontinued here…

At the end of an already long day a co-worker and I recently came across the problem that

new java.text.SimpleDateFormat("dd.MM.yyyy").parse("03.03.08");

does not return March 3rd, 2008 but March 3rd, 0008 instead.

As any decent engineers would, we headed for the respective API documentation right away to see whether there was an explanation for this behavior. Like any bad engineers, however, we didn’t pay close enough attention to the details in the documentation and tried to fix the problem with the wrong tools. Since our customer forces us to develop for the WebSphere platform, hence for an IBM Java runtime, we even suspected that this might be the cause for our confusion. Shame on us! We were barking up the wrong tree. It’s all there in the JavaDocs if you read it carefully: http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html#year:

“For parsing, if the number of pattern letters is more than 2, the year is interpreted literally, regardless of the number of digits. So using the pattern “MM/dd/yyyy”, “01/11/12″ parses to Jan 11, 12 A.D.”

Ok, that’s the explanation, but what is the solution if you need “03.03.08” or “03.03.2008” to be parsed into March 3rd, 2008? As so very often I needed to put some distance between myself and the problem (it dawned on me in the train on my way home). The pattern in this case needs to contain fewer or an equal number of letters for the year than the actual string to be parsed. The pattern “dd.MM.yy” interprets both the above examples as March 3rd, 2008.

For testing purposes I wrote a few lines of code to observe the behavior of the parse() method.

import java.text.*;
public class DateTest {
    private static final DateFormat parseFormat = new SimpleDateFormat("dd.MM.yy");
    private static final DateFormat formattingFormat = new SimpleDateFormat("dd.MM.yyyy");

    public static void main(String[] args) throws ParseException {
        test("3.3.08");
        test("3.3.2008");
        test("03.03.08");
        test("3.3.08xx");
        test("32.3.08");
        test("3.3.xx08");
    }

    private static void test(String dateString) throws ParseException {
        System.err.println(formattingFormat.format(parseFormat.parse(dateString)));
    }
}

produces

03.03.2008
03.03.2008
03.03.2008
03.03.2008
01.04.2008 // obvious, due to default lenient behavior
Exception in thread "main" java.text.ParseException: Unparseable date: "3.3.xx08"
	at java.text.DateFormat.parse(DateFormat.java:335)
	at DateTest.test(DateTest.java:16)
	at DateTest.main(DateTest.java:12)

6. April, 2008

iPod Touch, cannot buy January upgrade

Filed under: Apple & Mac — frightanic @ 09:30

This blog now resides at http://www.frightanic.com/. It will be discontinued here…

Back in January 2008 Apple released a software upgrade for the iPod Touch and the iPhone. As a result, whenever you plugged your iPod into your computer and wanted to sync it, iTunes would first show a page with the option to download and install the new package. I would have done so right away if Apple gave it away for free – for the iPod Touch they charge you $20 while it’s free for the iPhone. Hence, I only installed the 1.1.4 firmware upgrade but without unlocking the new apps that come with it. The “commercial” page advertising to new apps, however, got on my nerves, so I clicked some “don’t bother me with that stuff anymore” button.

To get to the point, yesterday I changed my mind. I wanted that software upgrade. So, I went to apple.com and clicked on the “Have an iPod touch without the new software?” link in the iPod section. It took me to the above mentioned page in iTunes (the iTunes store to be precise). However, there was no “buy now” button anywhere to be found, only an “OK” button at the bottom of the screen that just took me back to the iTunes store home page when clicked on.

I tried resetting the iPod, searched the Internet long and hard for solutions to that problem, and – among lots of others – came along a thread at tuaw.com and softpedia.com that looked promising. However, nothing seemed to cure my problem until I stumbled upon a thread over at ilounge.com. A user posted the direct link to the desired page in the iTunes store: http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=271872604&s=143441. I clicked the link, paid $20 in the iTunes store, and happily watched as the new apps got unlocked. Worked like a charm!

WARNING: just because this worked in my case doesn’t mean that it’ll work out for you! I’ve come along lots of threads where people complained that Apple double- and triple-charged them for the upgrade without installing the apps. Try at your own risk!

Blog at WordPress.com.