Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
AloqaIM-Android
Commits
c305afcf
Commit
c305afcf
authored
Nov 17, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set date label to Todat or Yesterday when applied for best readability
parent
82847d85
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
1 deletion
+20
-1
DateTime.java
app/src/main/java/chat/rocket/android/helper/DateTime.java
+20
-1
No files found.
app/src/main/java/chat/rocket/android/helper/DateTime.java
View file @
c305afcf
...
@@ -5,7 +5,10 @@ import android.text.format.DateFormat;
...
@@ -5,7 +5,10 @@ import android.text.format.DateFormat;
import
java.text.ParseException
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.time.Instant
;
import
java.time.temporal.ChronoUnit
;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.GregorianCalendar
;
import
java.util.GregorianCalendar
;
import
java.util.Locale
;
import
java.util.Locale
;
import
java.util.TimeZone
;
import
java.util.TimeZone
;
...
@@ -56,7 +59,7 @@ public class DateTime {
...
@@ -56,7 +59,7 @@ public class DateTime {
case
DAY:
case
DAY:
return
DAY_FORMAT
.
format
(
cal
.
getTime
());
return
DAY_FORMAT
.
format
(
cal
.
getTime
());
case
DATE:
case
DATE:
return
DATE_FORMAT
.
f
ormat
(
cal
.
getTime
());
return
getDateF
ormat
(
cal
.
getTime
());
case
TIME:
case
TIME:
return
TIME_FORMAT
.
format
(
cal
.
getTime
());
return
TIME_FORMAT
.
format
(
cal
.
getTime
());
case
DATE_TIME:
case
DATE_TIME:
...
@@ -81,6 +84,22 @@ public class DateTime {
...
@@ -81,6 +84,22 @@ public class DateTime {
}
}
}
}
private
static
String
getDateFormat
(
Date
dateTime
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
dateTime
);
Calendar
today
=
Calendar
.
getInstance
();
Calendar
yesterday
=
Calendar
.
getInstance
();
yesterday
.
add
(
Calendar
.
DATE
,
-
1
);
if
(
calendar
.
get
(
Calendar
.
YEAR
)
==
today
.
get
(
Calendar
.
YEAR
)
&&
calendar
.
get
(
Calendar
.
DAY_OF_YEAR
)
==
today
.
get
(
Calendar
.
DAY_OF_YEAR
))
{
return
"Today"
;
}
else
if
(
calendar
.
get
(
Calendar
.
YEAR
)
==
yesterday
.
get
(
Calendar
.
YEAR
)
&&
calendar
.
get
(
Calendar
.
DAY_OF_YEAR
)
==
yesterday
.
get
(
Calendar
.
DAY_OF_YEAR
))
{
return
"Yesterday"
;
}
else
{
return
DATE_FORMAT
.
format
(
dateTime
);
}
}
/**
/**
* parse datetime string to ms.
* parse datetime string to ms.
*/
*/
...
...
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