-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing timestamp conversion bug (#9)
* Fixing timestamp conversion bug * Implementing new date formatter to fix timezone bug.
- Loading branch information
Showing
5 changed files
with
27 additions
and
14 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
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
20 changes: 15 additions & 5 deletions
20
core/src/main/java/com/oxeanbits/forecastchart/core/util/DateFormatter.kt
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 |
---|---|---|
@@ -1,12 +1,22 @@ | ||
package com.oxeanbits.forecastchart.core.util | ||
|
||
import java.text.SimpleDateFormat | ||
import java.util.Date | ||
import org.threeten.bp.Instant | ||
import org.threeten.bp.LocalDate | ||
import org.threeten.bp.LocalDateTime | ||
import org.threeten.bp.ZoneOffset | ||
import org.threeten.bp.format.DateTimeFormatter | ||
|
||
|
||
object DateFormatter{ | ||
|
||
fun stringToTimestamp(date: String): Float{ | ||
return LocalDate.parse(date).atStartOfDay() | ||
.toInstant(ZoneOffset.UTC).epochSecond.toFloat() | ||
} | ||
|
||
fun timestampToDate(timestamp: Long): String{ | ||
val mDate = Date() | ||
mDate.time = (timestamp.times(1000)) | ||
return SimpleDateFormat("yyyy-MM-dd").format(mDate) | ||
val mDate = LocalDateTime.ofInstant(Instant.ofEpochSecond(timestamp), ZoneOffset.UTC) | ||
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") | ||
return mDate.format(formatter) | ||
} | ||
} |