-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from kpartlow/master
Moved over more types OffsetDateTime, OffsetTime, Year, added tests.
- Loading branch information
Showing
17 changed files
with
644 additions
and
73 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
70 changes: 64 additions & 6 deletions
70
src/main/java/com/cedarsoftware/util/convert/Converter.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
95 changes: 95 additions & 0 deletions
95
src/main/java/com/cedarsoftware/util/convert/OffsetDateTimeConversions.java
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.cedarsoftware.util.convert; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
import java.sql.Timestamp; | ||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import java.time.OffsetDateTime; | ||
import java.time.OffsetTime; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.GregorianCalendar; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import java.util.stream.Stream; | ||
|
||
public class OffsetDateTimeConversions { | ||
private OffsetDateTimeConversions() {} | ||
|
||
static OffsetDateTime toDifferentZone(Object from, ConverterOptions options) { | ||
OffsetDateTime offsetDateTime = (OffsetDateTime) from; | ||
return offsetDateTime.toInstant().atZone(options.getZoneId()).toOffsetDateTime(); | ||
} | ||
|
||
static Instant toInstant(Object from) { | ||
return ((OffsetDateTime)from).toInstant(); | ||
} | ||
|
||
static long toLong(Object from) { | ||
return toInstant(from).toEpochMilli(); | ||
} | ||
|
||
static long toLong(Object from, Converter converter, ConverterOptions options) { | ||
return toLong(from); | ||
} | ||
|
||
static Instant toInstant(Object from, Converter converter, ConverterOptions options) { | ||
return toInstant(from); | ||
} | ||
|
||
static LocalDateTime toLocalDateTime(Object from, Converter converter, ConverterOptions options) { | ||
return toDifferentZone(from, options).toLocalDateTime(); | ||
} | ||
|
||
static LocalDate toLocalDate(Object from, Converter converter, ConverterOptions options) { | ||
return toDifferentZone(from, options).toLocalDate(); | ||
} | ||
|
||
static LocalTime toLocalTime(Object from, Converter converter, ConverterOptions options) { | ||
return toDifferentZone(from, options).toLocalTime(); | ||
} | ||
|
||
static AtomicLong toAtomicLong(Object from, Converter converter, ConverterOptions options) { | ||
return new AtomicLong(toLong(from)); | ||
} | ||
|
||
static Timestamp toTimestamp(Object from, Converter converter, ConverterOptions options) { | ||
return new Timestamp(toLong(from)); | ||
} | ||
|
||
static Calendar toCalendar(Object from, Converter converter, ConverterOptions options) { | ||
Calendar calendar = Calendar.getInstance(options.getTimeZone()); | ||
calendar.setTimeInMillis(toLong(from)); | ||
return calendar; | ||
} | ||
|
||
static java.sql.Date toSqlDate(Object from, Converter converter, ConverterOptions options) { | ||
return new java.sql.Date(toLong(from)); | ||
} | ||
|
||
static Date toDate(Object from, Converter converter, ConverterOptions options) { | ||
return new Date(toLong(from)); | ||
} | ||
|
||
static BigInteger toBigInteger(Object from, Converter converter, ConverterOptions options) { | ||
return BigInteger.valueOf(toLong(from)); | ||
} | ||
|
||
static BigDecimal toBigDecimal(Object from, Converter converter, ConverterOptions options) { | ||
return BigDecimal.valueOf(toLong(from)); | ||
} | ||
|
||
static OffsetTime toOffsetTime(Object from, Converter converter, ConverterOptions options) { | ||
OffsetDateTime dateTime = (OffsetDateTime) from; | ||
return dateTime.toOffsetTime(); | ||
} | ||
|
||
static String toString(Object from, Converter converter, ConverterOptions options) { | ||
OffsetDateTime offsetDateTime = (OffsetDateTime) from; | ||
return offsetDateTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME); | ||
} | ||
} |
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
66 changes: 66 additions & 0 deletions
66
src/main/java/com/cedarsoftware/util/convert/YearConversions.java
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.cedarsoftware.util.convert; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
import java.sql.Timestamp; | ||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import java.time.Year; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.GregorianCalendar; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
public class YearConversions { | ||
private YearConversions() {} | ||
|
||
static int toInt(Object from) { | ||
return ((Year)from).getValue(); | ||
} | ||
|
||
static long toLong(Object from, Converter converter, ConverterOptions options) { | ||
return toInt(from); | ||
} | ||
|
||
static int toInt(Object from, Converter converter, ConverterOptions options) { | ||
return toInt(from); | ||
} | ||
|
||
static AtomicInteger toAtomicInteger(Object from, Converter converter, ConverterOptions options) { | ||
return new AtomicInteger(toInt(from)); | ||
} | ||
|
||
static AtomicLong toAtomicLong(Object from, Converter converter, ConverterOptions options) { | ||
return new AtomicLong(toInt(from)); | ||
} | ||
|
||
static double toDouble(Object from, Converter converter, ConverterOptions options) { | ||
return toInt(from); | ||
} | ||
|
||
static boolean toBoolean(Object from, Converter converter, ConverterOptions options) { | ||
return toInt(from) == 0; | ||
} | ||
|
||
static AtomicBoolean toAtomicBoolean(Object from, Converter converter, ConverterOptions options) { | ||
return new AtomicBoolean(toInt(from) == 0); | ||
} | ||
|
||
static BigInteger toBigInteger(Object from, Converter converter, ConverterOptions options) { | ||
return BigInteger.valueOf(toInt(from)); | ||
} | ||
|
||
static BigDecimal toBigDecimal(Object from, Converter converter, ConverterOptions options) { | ||
return BigDecimal.valueOf(toInt(from)); | ||
} | ||
|
||
static String toString(Object from, Converter converter, ConverterOptions options) { | ||
return ((Year)from).toString(); | ||
} | ||
} |
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
Oops, something went wrong.