Skip to content

Commit

Permalink
NSDateFormatter is not thread safe according to http://developer.appl…
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Sep 13, 2012
1 parent 5d51e77 commit 3947847
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions source/ch/cyberduck/ui/cocoa/UserDefaultsDateFormatter.java
Expand Up @@ -124,14 +124,16 @@ private static NSDate toDate(long milliseconds) {
* @param natural Use natural language
* @return A short format string or "Unknown" if there is a problem converting the time to a string
*/
public synchronized String getShortFormat(final long milliseconds, boolean natural) {
if(-1 == milliseconds) {
return Locale.localizedString("Unknown");
public String getShortFormat(final long milliseconds, boolean natural) {
synchronized(shortDateFormatter) {
if(-1 == milliseconds) {
return Locale.localizedString("Unknown");
}
if(natural) {
return shortDateNaturalFormatter.stringFromDate(toDate(milliseconds));
}
return shortDateFormatter.stringFromDate(toDate(milliseconds));
}
if(natural) {
return shortDateNaturalFormatter.stringFromDate(toDate(milliseconds));
}
return shortDateFormatter.stringFromDate(toDate(milliseconds));
}

/**
Expand All @@ -141,14 +143,16 @@ public synchronized String getShortFormat(final long milliseconds, boolean natur
* @param natural Use natural language
* @return A medium format string or "Unknown" if there is a problem converting the time to a string
*/
public synchronized String getMediumFormat(final long milliseconds, boolean natural) {
if(-1 == milliseconds) {
return Locale.localizedString("Unknown");
}
if(natural) {
return mediumDateNaturalFormatter.stringFromDate(toDate(milliseconds));
public String getMediumFormat(final long milliseconds, boolean natural) {
synchronized(mediumDateFormatter) {
if(-1 == milliseconds) {
return Locale.localizedString("Unknown");
}
if(natural) {
return mediumDateNaturalFormatter.stringFromDate(toDate(milliseconds));
}
return mediumDateFormatter.stringFromDate(toDate(milliseconds));
}
return mediumDateFormatter.stringFromDate(toDate(milliseconds));
}

/**
Expand All @@ -158,13 +162,15 @@ public synchronized String getMediumFormat(final long milliseconds, boolean natu
* @param natural Use natural language
* @return A long format string or "Unknown" if there is a problem converting the time to a string
*/
public synchronized String getLongFormat(final long milliseconds, boolean natural) {
if(-1 == milliseconds) {
return Locale.localizedString("Unknown");
}
if(natural) {
return longDateNaturalFormatter.stringFromDate(toDate(milliseconds));
public String getLongFormat(final long milliseconds, boolean natural) {
synchronized(longDateFormatter) {
if(-1 == milliseconds) {
return Locale.localizedString("Unknown");
}
if(natural) {
return longDateNaturalFormatter.stringFromDate(toDate(milliseconds));
}
return longDateFormatter.stringFromDate(toDate(milliseconds));
}
return longDateFormatter.stringFromDate(toDate(milliseconds));
}
}

0 comments on commit 3947847

Please sign in to comment.