matyb/java-koans — Issue #20: AboutDates:  usingDateFormatToParseDates()
Author: kjc
Created: 2011-11-13 23:17:48+00:00
State: open

Line 68: The hard-coded date string fed to `dateFormat.parse()` cannot be parsed (Java 1.6.0_18).

```java

@Koan
public void usingDateFormatToParseDates() throws ParseException {
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
Date date2 = dateFormat.parse("Sat Sep 01 12:34:46 CET 2001");
assertEquals(date2.toString(), __);
// What happened to the time? What do you need to change to keep the time as well?
}
```

After much trial and error, I found a date _and time_ format that parsed:

```java
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
Date date2 = dateFormat.parse("Saturday, September 1, 2001 12:34:46 pm CET");
```

Error produced before the change:

```
Ponder what's going wrong in the: AboutDates class's usingDateFormatToParseDates method.

Line 68 may offer a clue as to how you may progress, now make haste!
What went wrong:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.sandwich.koan.runner.KoanMethodRunner.run(KoanMethodRunner.java:28)
at com.sandwich.koan.runner.RunKoans.runKoans(RunKoans.java:67)
at com.sandwich.koan.runner.RunKoans.run(RunKoans.java:40)
at com.sandwich.koan.constant.ArgumentType.run(ArgumentType.java:74)
at com.sandwich.koan.cmdline.CommandLineArgument.run(CommandLineArgument.java:36)
at com.sandwich.koan.cmdline.CommandLineArgumentRunner.run(CommandLineArgumentRunner.java:26)
at com.sandwich.util.io.KoanFileCompileAndRunListener.fileSaved(KoanFileCompileAndRunListener.java:37)
at com.sandwich.util.io.FileMonitor.notifyListeners(FileMonitor.java:57)
at com.sandwich.util.io.FileMonitorFactory$1.run(FileMonitorFactory.java:29)
at java.lang.Thread.run(Thread.java:636)
Caused by: java.text.ParseException: Unparseable date: "Sat Sep 01 12:34:46 CET 2001"
at java.text.DateFormat.parse(DateFormat.java:354)
at intermediate.AboutDates.usingDateFormatToParseDates(AboutDates.java:68)
... 14 more
```