-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
26 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 |
---|---|---|
|
@@ -6,14 +6,18 @@ | |
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
import com.cedarsoftware.util.CompactLinkedMap; | ||
|
||
import static com.cedarsoftware.util.convert.Converter.VALUE; | ||
|
||
/** | ||
* @author Kenny Partlow ([email protected]) | ||
* <br> | ||
|
@@ -47,14 +51,6 @@ static LocalDateTime toLocalDateTime(Object from, Converter converter) { | |
return toZonedDateTime(from, converter).toLocalDateTime(); | ||
} | ||
|
||
static LocalDate toLocalDate(Object from, Converter converter) { | ||
return toZonedDateTime(from, converter).toLocalDate(); | ||
} | ||
|
||
static LocalTime toLocalTime(Object from, Converter converter) { | ||
return toZonedDateTime(from, converter).toLocalTime(); | ||
} | ||
|
||
static ZonedDateTime toZonedDateTime(Object from, Converter converter) { | ||
ZoneId zoneId = converter.getOptions().getZoneId(); | ||
return ((LocalDate) from).atStartOfDay(zoneId); | ||
|
@@ -69,7 +65,8 @@ static AtomicLong toAtomicLong(Object from, Converter converter) { | |
} | ||
|
||
static Timestamp toTimestamp(Object from, Converter converter) { | ||
return new Timestamp(toLong(from, converter)); | ||
LocalDate localDate = (LocalDate) from; | ||
return new Timestamp(localDate.toEpochDay() * 86400 * 1000); | ||
} | ||
|
||
static Calendar toCalendar(Object from, Converter converter) { | ||
|
@@ -101,4 +98,11 @@ static String toString(Object from, Converter converter) { | |
LocalDate localDate = (LocalDate) from; | ||
return localDate.format(DateTimeFormatter.ISO_LOCAL_DATE); | ||
} | ||
|
||
static Map<String, Object> toMap(Object from, Converter converter) { | ||
LocalDate localDate = (LocalDate) from; | ||
Map<String, Object> target = new CompactLinkedMap<>(); | ||
target.put(VALUE, localDate.toString()); | ||
return target; | ||
} | ||
} |
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