Skip to content

Commit

Permalink
Conversion tests finished, 1.0. All 686 cross product conversions are…
Browse files Browse the repository at this point in the history
… now tested.
  • Loading branch information
jdereg committed Mar 21, 2024
1 parent 75d5241 commit c423d42
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ private static void buildFactoryConversions() {
CONVERSION_DB.put(pair(LocalDate.class, OffsetDateTime.class), LocalDateConversions::toOffsetDateTime);
CONVERSION_DB.put(pair(Instant.class, OffsetDateTime.class), InstantConversions::toOffsetDateTime);
CONVERSION_DB.put(pair(ZonedDateTime.class, OffsetDateTime.class), ZonedDateTimeConversions::toOffsetDateTime);
CONVERSION_DB.put(pair(LocalDateTime.class, OffsetDateTime.class), LocalDateTimeConversions::toOffsetDateTime);

// toOffsetTime
CONVERSION_DB.put(pair(Void.class, OffsetTime.class), VoidConversions::toNull);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
Expand Down Expand Up @@ -42,6 +44,12 @@ static ZonedDateTime toZonedDateTime(Object from, Converter converter) {
return ZonedDateTime.of(ldt, converter.getOptions().getZoneId());
}

static OffsetDateTime toOffsetDateTime(Object from, Converter converter) {
LocalDateTime ldt = (LocalDateTime) from;
ZoneOffset zoneOffset = ZoneOffset.ofTotalSeconds(converter.getOptions().getTimeZone().getOffset(System.currentTimeMillis()) / 1000);
return ldt.atOffset(zoneOffset);
}

static Instant toInstant(Object from, Converter converter) {
return toZonedDateTime(from, converter).toInstant();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static float toFloat(Object from, Converter converter) {
}

static AtomicBoolean toAtomicBoolean(Object from, Converter converter) {
return new AtomicBoolean(toInt(from, converter) == 0);
return new AtomicBoolean(toInt(from, converter) != 0);
}

static BigInteger toBigInteger(Object from, Converter converter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import com.cedarsoftware.util.CompactLinkedMap;

import static com.cedarsoftware.util.convert.MapConversions.HOURS;
import static com.cedarsoftware.util.convert.MapConversions.MINUTES;

/**
* @author John DeRegnaucourt ([email protected])
* <br>
Expand Down Expand Up @@ -35,8 +38,8 @@ static Map toMap(Object from, Converter converter) {
int hours = totalSeconds / 3600;
int minutes = (totalSeconds % 3600) / 60;
int seconds = totalSeconds % 60;
target.put("hours", hours);
target.put("minutes", minutes);
target.put(HOURS, hours);
target.put(MINUTES, minutes);
if (seconds != 0) {
target.put("seconds", seconds);
}
Expand Down
Loading

0 comments on commit c423d42

Please sign in to comment.