Skip to content

Commit d69a8ee

Browse files
Fixed date formatter
1 parent 42e2819 commit d69a8ee

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ and the dependency:
2323
<dependency>
2424
<groupId>com.mauriciotogneri</groupId>
2525
<artifactId>javautils</artifactId>
26-
<version>0.5.0</version>
26+
<version>0.6.0</version>
2727
</dependency>
2828
```
2929

@@ -32,6 +32,6 @@ or if you use Gradle:
3232
```groovy
3333
dependencies
3434
{
35-
compile 'com.mauriciotogneri:javautils:0.5.0'
35+
compile 'com.mauriciotogneri:javautils:0.6.0'
3636
}
3737
```

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<modelVersion>4.0.0</modelVersion>
88
<groupId>com.mauriciotogneri</groupId>
99
<artifactId>javautils</artifactId>
10-
<version>0.5.0</version>
10+
<version>0.6.0</version>
1111
<name>Java Utils</name>
1212
<packaging>jar</packaging>
1313
<url>https://github.com/mauriciotogneri/java-utils</url>

src/main/java/com/mauriciotogneri/javautils/FormattedDateTime.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,18 @@ private DateTimeParser[] parsers(String pattern, String... patterns)
5858

5959
public String date(DateTime dateTime, DateTimeZone timeZone, Locale locale, String defaultValue)
6060
{
61-
try
61+
if ((dateTime != null) && (timeZone != null) && (locale != null))
6262
{
63-
return formatter.withZone(timeZone).withLocale(locale).print(dateTime);
63+
try
64+
{
65+
return formatter.withZone(timeZone).withLocale(locale).print(dateTime);
66+
}
67+
catch (Exception e)
68+
{
69+
return defaultValue;
70+
}
6471
}
65-
catch (Exception e)
72+
else
6673
{
6774
return defaultValue;
6875
}
@@ -87,11 +94,18 @@ public String date(DateTime dateTime, Locale locale)
8794

8895
public DateTime date(String timestamp, DateTimeZone timeZone, DateTime defaultValue)
8996
{
90-
try
97+
if ((timestamp != null) && (timeZone != null))
9198
{
92-
return formatter.withZone(timeZone).parseDateTime(timestamp);
99+
try
100+
{
101+
return formatter.withZone(timeZone).parseDateTime(timestamp);
102+
}
103+
catch (Exception e)
104+
{
105+
return defaultValue;
106+
}
93107
}
94-
catch (Exception e)
108+
else
95109
{
96110
return defaultValue;
97111
}

0 commit comments

Comments
 (0)