forked from bcgit/bc-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
599 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
core/src/main/jdk1.1/org/bouncycastle/asn1/LocaleUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.bouncycastle.asn1; | ||
|
||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
import org.bouncycastle.util.Longs; | ||
|
||
/** | ||
* ASN.1 uses an EN locale for its internal formatting. This class finds the nearest equivalent in the | ||
* current JVM to ensure date formats are always respected. | ||
*/ | ||
public class LocaleUtil | ||
{ | ||
private static final Map localeCache = new HashMap(); | ||
|
||
public static Locale EN_Locale = forEN(); | ||
|
||
private static Locale forEN() | ||
{ | ||
if ("en".equalsIgnoreCase(Locale.getDefault().getLanguage())) | ||
{ | ||
return Locale.getDefault(); | ||
} | ||
|
||
/* | ||
Locale[] locales = Locale.getAvailableLocales(); | ||
for (int i = 0; i != locales.length; i++) | ||
{ | ||
if ("en".equalsIgnoreCase(locales[i].getLanguage())) | ||
{ | ||
return locales[i]; | ||
} | ||
} | ||
*/ | ||
return Locale.getDefault(); | ||
} | ||
|
||
static Date epochAdjust(Date date) | ||
throws ParseException | ||
{ | ||
Locale locale = Locale.getDefault(); | ||
if (locale == null) | ||
{ | ||
return date; | ||
} | ||
|
||
synchronized (localeCache) | ||
{ | ||
Long adj = (Long)localeCache.get(locale); | ||
|
||
if (adj == null) | ||
{ | ||
SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmssz"); | ||
long v = dateF.parse("19700101000000GMT+00:00").getTime(); | ||
|
||
adj = longValueOf(v); | ||
|
||
localeCache.put(locale, adj); | ||
} | ||
|
||
if (adj.longValue() != 0L) | ||
{ | ||
return new Date(date.getTime() - adj.longValue()); | ||
} | ||
|
||
return date; | ||
} | ||
} | ||
|
||
private static Long longValueOf(long v) | ||
{ | ||
return Longs.valueOf(v); | ||
} | ||
} |
Oops, something went wrong.