Skip to content

Commit

Permalink
Fixed missing timezone bugs. Added support for test date to come from…
Browse files Browse the repository at this point in the history
… lambda Suppliers, allowing for Turing complete source data for tests. Added detection for when source class and target class are the same - identity check is performed. Added the bulk of the toString conversions tests.
  • Loading branch information
jdereg committed Feb 6, 2024
1 parent 627e360 commit dd40b6e
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.cedarsoftware.util.convert;

import com.cedarsoftware.util.StringUtilities;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;

Expand Down Expand Up @@ -35,8 +33,7 @@ static CharBuffer toCharBuffer(Object from, ConverterOptions options) {
ByteBuffer buffer = asReadOnlyBuffer(from);
return options.getCharset().decode(buffer);
}



static CharBuffer toCharBuffer(Object from, Converter converter, ConverterOptions options) {
return toCharBuffer(from, options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.concurrent.atomic.AtomicLong;

/**
Expand Down Expand Up @@ -119,6 +118,7 @@ static Calendar create(long epochMilli, ConverterOptions options) {

static String toString(Object from, Converter converter, ConverterOptions options) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
simpleDateFormat.setTimeZone(options.getTimeZone());
return simpleDateFormat.format(((Calendar) from).getTime());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.atomic.AtomicLong;
Expand Down Expand Up @@ -101,16 +100,19 @@ static AtomicLong toAtomicLong(Object from, Converter converter, ConverterOption

static String dateToString(Object from, Converter converter, ConverterOptions options) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
simpleDateFormat.setTimeZone(options.getTimeZone());
return simpleDateFormat.format(((Date) from));
}

static String sqlDateToString(Object from, Converter converter, ConverterOptions options) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
simpleDateFormat.setTimeZone(options.getTimeZone());
return simpleDateFormat.format(((Date) from));
}

static String timestampToString(Object from, Converter converter, ConverterOptions options) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
simpleDateFormat.setTimeZone(options.getTimeZone());
return simpleDateFormat.format(((Date) from));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -87,9 +86,13 @@ static float toFloat(Object from, Converter converter, ConverterOptions options)
static Float toFloatZero(Object from, Converter converter, ConverterOptions options) {
return CommonValues.FLOAT_ZERO;
}

static String floatToString(Object from, Converter converter, ConverterOptions option) {
return new DecimalFormat("#.####################").format(from);
float x = (float) from;
if (x == 0f) {
return "0";
}
return from.toString();
}

static double toDouble(Object from, Converter converter, ConverterOptions options) {
Expand All @@ -105,7 +108,11 @@ static Double toDoubleZero(Object from, Converter converter, ConverterOptions op
}

static String doubleToString(Object from, Converter converter, ConverterOptions option) {
return new DecimalFormat("#.####################").format(from);
double x = (double) from;
if (x == 0d) {
return "0";
}
return from.toString();
}

static BigDecimal integerTypeToBigDecimal(Object from, Converter converter, ConverterOptions options) {
Expand Down
Loading

0 comments on commit dd40b6e

Please sign in to comment.