Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
4ae8656b
Commit
4ae8656b
authored
Mar 09, 2017
by
Feng Xiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make JsonFormat locale independent.
parent
fa178802
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
4 deletions
+11
-4
Timestamps.java
...il/src/main/java/com/google/protobuf/util/Timestamps.java
+5
-4
JsonFormatTest.java
...rc/test/java/com/google/protobuf/util/JsonFormatTest.java
+6
-0
No files found.
java/util/src/main/java/com/google/protobuf/util/Timestamps.java
View file @
4ae8656b
...
...
@@ -44,6 +44,7 @@ import java.text.SimpleDateFormat;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.GregorianCalendar
;
import
java.util.Locale
;
import
java.util.TimeZone
;
/**
...
...
@@ -83,7 +84,7 @@ public final class Timestamps {
};
private
static
SimpleDateFormat
createTimestampFormat
()
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss"
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss"
,
Locale
.
ENGLISH
);
GregorianCalendar
calendar
=
new
GregorianCalendar
(
TimeZone
.
getTimeZone
(
"UTC"
));
// We use Proleptic Gregorian Calendar (i.e., Gregorian calendar extends
// backwards to year one) for timestamp formating.
...
...
@@ -386,11 +387,11 @@ public final class Timestamps {
static
String
formatNanos
(
int
nanos
)
{
// Determine whether to use 3, 6, or 9 digits for the nano part.
if
(
nanos
%
NANOS_PER_MILLISECOND
==
0
)
{
return
String
.
format
(
"%1$03d"
,
nanos
/
NANOS_PER_MILLISECOND
);
return
String
.
format
(
Locale
.
ENGLISH
,
"%1$03d"
,
nanos
/
NANOS_PER_MILLISECOND
);
}
else
if
(
nanos
%
NANOS_PER_MICROSECOND
==
0
)
{
return
String
.
format
(
"%1$06d"
,
nanos
/
NANOS_PER_MICROSECOND
);
return
String
.
format
(
Locale
.
ENGLISH
,
"%1$06d"
,
nanos
/
NANOS_PER_MICROSECOND
);
}
else
{
return
String
.
format
(
"%1$09d"
,
nanos
);
return
String
.
format
(
Locale
.
ENGLISH
,
"%1$09d"
,
nanos
);
}
}
}
java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java
View file @
4ae8656b
...
...
@@ -65,10 +65,16 @@ import java.io.IOException;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Map
;
import
junit.framework.TestCase
;
public
class
JsonFormatTest
extends
TestCase
{
public
JsonFormatTest
()
{
// Test that locale does not affect JsonFormat.
Locale
.
setDefault
(
Locale
.
forLanguageTag
(
"hi-IN"
));
}
private
void
setAllFields
(
TestAllTypes
.
Builder
builder
)
{
builder
.
setOptionalInt32
(
1234
);
builder
.
setOptionalInt64
(
1234567890123456789L
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment