Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghislain Fourny committed Jul 7, 2023
1 parent 52def99 commit f46ce37
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/rumbledb/items/DateItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public DateItem() {
super();
this.value = value;
this.hasTimeZone = hasTimeZone;
if (!hasTimeZone) {
this.value = this.value.withZoneRetainFields(DateTimeZone.UTC);
}

}

DateItem(String dateTimeString) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/rumbledb/items/DateTimeItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public DateTimeItem() {
super();
this.value = value;
this.hasTimeZone = hasTimeZone;
if (!hasTimeZone) {
this.value = this.value.withZoneRetainFields(DateTimeZone.UTC);
}

}

DateTimeItem(String dateTimeString) {
Expand Down
25 changes: 20 additions & 5 deletions src/main/java/org/rumbledb/items/TimeItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public TimeItem() {
super();
this.value = value;
this.hasTimeZone = hasTimeZone;
if (!hasTimeZone) {
this.value = this.value.withZoneRetainFields(DateTimeZone.UTC);
}
}

TimeItem(String dateTimeString) {
Expand Down Expand Up @@ -87,12 +90,24 @@ public int hashCode() {

@Override
public String getStringValue() {
String value = this.value.toString();
String zoneString = this.value.getZone() == DateTimeZone.UTC ? "Z" : value.substring(value.length() - 6);
value = value.substring(0, value.length() - zoneString.length());
String originalValue = this.value.toString();
if (!hasTimeZone()) {
String value = originalValue.substring(0, originalValue.length() - 1);
value = this.value.getMillisOfSecond() == 0 ? value.substring(0, value.length() - 4) : value;
value = value.substring(value.indexOf("T") + 1);;
return value;
}
if (this.value.getZone() == DateTimeZone.UTC) {
String value = originalValue.substring(0, originalValue.length() - 1);
value = this.value.getMillisOfSecond() == 0 ? value.substring(0, value.length() - 4) : value;
value = value.substring(value.indexOf("T") + 1);;
return value + "Z";
}
String zoneString = originalValue.substring(originalValue.length() - 6);
String value = originalValue.substring(0, originalValue.length() - 6);
value = this.value.getMillisOfSecond() == 0 ? value.substring(0, value.length() - 4) : value;
int dateTimeSeparatorIndex = value.indexOf("T");
return value.substring(dateTimeSeparatorIndex + 1) + (this.hasTimeZone ? zoneString : "");
value = value.substring(value.indexOf("T") + 1);;
return value + zoneString;
}

@Override
Expand Down

0 comments on commit f46ce37

Please sign in to comment.