forked from pepegar/hammock
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves pepegar#93
- Loading branch information
Showing
6 changed files
with
23 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package hammock | ||
package hi | ||
|
||
import java.util.{Date => JavaDate} | ||
import java.time.ZonedDateTime | ||
import scalajs.js.{Date => JsDate} | ||
|
||
object platformspecific { | ||
def convert(d: JavaDate): JsDate = new JsDate(d.getTime().toDouble) | ||
def convert(d: ZonedDateTime): JsDate = new JsDate(d.toInstant.toEpochMilli.toDouble) | ||
|
||
implicit object JSDateFormatter extends DateFormatter { | ||
def format(date: JavaDate): String = fmt(convert(date)) | ||
def format(date: ZonedDateTime): String = fmt(convert(date)) | ||
|
||
def fmt(date: JsDate): String = date.toString | ||
def fmt(date: JsDate): String = date.toUTCString | ||
} | ||
} |
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,12 @@ | ||
package hammock | ||
package hi | ||
|
||
import java.text.SimpleDateFormat | ||
import java.util.Date | ||
import java.time.ZonedDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
object platformspecific { | ||
implicit object JVMDateFormatter extends DateFormatter { | ||
private val fmt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z") | ||
def format(date: Date): String = fmt.format(date) | ||
private val fmt = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss O") | ||
def format(date: ZonedDateTime): String = date.format(fmt) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package hammock | ||
package hi | ||
|
||
import java.util.Date | ||
import java.time.ZonedDateTime | ||
|
||
trait DateFormatter { | ||
def format(date: Date): String | ||
def format(date: ZonedDateTime): String | ||
} |
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