Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
8db5e264
Commit
8db5e264
authored
Jun 19, 2017
by
Jason Song
Committed by
GitHub
Jun 19, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #642 from lepdou/bugfix_relativedate
Bugfix: relative date format calculate error
parents
5bcb4095
cde72fac
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
1 deletion
+26
-1
RelativeDateFormat.java
...trip/framework/apollo/portal/util/RelativeDateFormat.java
+26
-1
No files found.
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RelativeDateFormat.java
View file @
8db5e264
...
@@ -2,6 +2,7 @@ package com.ctrip.framework.apollo.portal.util;
...
@@ -2,6 +2,7 @@ package com.ctrip.framework.apollo.portal.util;
import
org.apache.commons.lang.time.FastDateFormat
;
import
org.apache.commons.lang.time.FastDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.Date
;
...
@@ -35,9 +36,15 @@ public class RelativeDateFormat {
...
@@ -35,9 +36,15 @@ public class RelativeDateFormat {
long
hours
=
toHours
(
delta
);
long
hours
=
toHours
(
delta
);
return
(
hours
<=
0
?
1
:
hours
)
+
ONE_HOUR_AGO
;
return
(
hours
<=
0
?
1
:
hours
)
+
ONE_HOUR_AGO
;
}
}
if
(
delta
<
48L
*
ONE_HOUR
)
{
Date
lastDayBeginTime
=
getDateOffset
(-
1
);
if
(
date
.
after
(
lastDayBeginTime
))
{
return
"昨天"
;
return
"昨天"
;
}
}
Date
lastTwoDaysBeginTime
=
getDateOffset
(-
2
);
if
(
date
.
after
(
lastTwoDaysBeginTime
))
{
return
"前天"
;
}
if
(
delta
<
30L
*
ONE_DAY
)
{
if
(
delta
<
30L
*
ONE_DAY
)
{
long
days
=
toDays
(
delta
);
long
days
=
toDays
(
delta
);
return
(
days
<=
0
?
1
:
days
)
+
ONE_DAY_AGO
;
return
(
days
<=
0
?
1
:
days
)
+
ONE_DAY_AGO
;
...
@@ -71,4 +78,22 @@ public class RelativeDateFormat {
...
@@ -71,4 +78,22 @@ public class RelativeDateFormat {
return
toDays
(
date
)
/
30L
;
return
toDays
(
date
)
/
30L
;
}
}
public
static
Date
getDateOffset
(
int
offset
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
new
Date
());
calendar
.
add
(
calendar
.
DATE
,
offset
);
return
getDayBeginTime
(
calendar
.
getTime
());
}
private
static
Date
getDayBeginTime
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
set
(
Calendar
.
HOUR
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
new
Date
(
calendar
.
getTime
().
getTime
());
}
}
}
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