public static DateTimeValue OfEpoch(IntegralValue epochSecondUTC, IntegralValue nano) { long ns = safeCastIntegral("nanosecond", nano, 0); if (ns < 0 || ns >= 1000_000_000) { throw new InvalidValuesArgumentException("Invalid nanosecond: " + ns); } return(new DateTimeValue(DatetimeRaw(epochSecondUTC.LongValue(), ns, UTC))); }
public override bool Equals(Value other) { if (other is IntegralValue) { IntegralValue that = ( IntegralValue )other; return(this.LongValue() == that.LongValue()); } else if (other is FloatingPointValue) { FloatingPointValue that = ( FloatingPointValue )other; return(NumberValues.NumbersEqual(that.DoubleValue(), this.LongValue())); } else { return(false); } }
public override int CompareTo(IntegralValue other) { return(Long.compare(LongValue(), other.LongValue())); }
public override DateTimeValue buildInternal() { bool selectingDate = fields.containsKey(TemporalFields.Date); bool selectingTime = fields.containsKey(TemporalFields.Time); bool selectingDateTime = fields.containsKey(TemporalFields.Datetime); bool selectingEpoch = fields.containsKey(TemporalFields.EpochSeconds) || fields.containsKey(TemporalFields.EpochMillis); bool selectingTimeZone; ZonedDateTime result; if (selectingDateTime) { AnyValue dtField = fields.get(TemporalFields.Datetime); if (!(dtField is TemporalValue)) { throw new InvalidValuesArgumentException(string.Format("Cannot construct date time from: {0}", dtField)); } TemporalValue dt = ( TemporalValue )dtField; LocalTime timePart = dt.getTimePart(_defaultZone).toLocalTime(); ZoneId zoneId = dt.getZoneId(_defaultZone); result = ZonedDateTime.of(dt.DatePart, timePart, zoneId); selectingTimeZone = dt.supportsTimeZone(); } else if (selectingEpoch) { if (fields.containsKey(TemporalFields.EpochSeconds)) { AnyValue epochField = fields.get(TemporalFields.EpochSeconds); if (!(epochField is IntegralValue)) { throw new InvalidValuesArgumentException(string.Format("Cannot construct date time from: {0}", epochField)); } IntegralValue epochSeconds = ( IntegralValue )epochField; result = AssertValidArgument(() => ZonedDateTime.ofInstant(Instant.ofEpochMilli(epochSeconds.LongValue() * 1000), timezone())); } else { AnyValue epochField = fields.get(TemporalFields.EpochMillis); if (!(epochField is IntegralValue)) { throw new InvalidValuesArgumentException(string.Format("Cannot construct date time from: {0}", epochField)); } IntegralValue epochMillis = ( IntegralValue )epochField; result = AssertValidArgument(() => ZonedDateTime.ofInstant(Instant.ofEpochMilli(epochMillis.LongValue()), timezone())); } selectingTimeZone = false; } else if (selectingTime || selectingDate) { LocalTime time; ZoneId zoneId; if (selectingTime) { AnyValue timeField = fields.get(TemporalFields.Time); if (!(timeField is TemporalValue)) { throw new InvalidValuesArgumentException(string.Format("Cannot construct time from: {0}", timeField)); } TemporalValue t = ( TemporalValue )timeField; time = t.getTimePart(_defaultZone).toLocalTime(); zoneId = t.getZoneId(_defaultZone); selectingTimeZone = t.supportsTimeZone(); } else { time = LocalTimeValue.DefaultLocalTime; zoneId = timezone(); selectingTimeZone = false; } LocalDate date; if (selectingDate) { AnyValue dateField = fields.get(TemporalFields.Date); if (!(dateField is TemporalValue)) { throw new InvalidValuesArgumentException(string.Format("Cannot construct date from: {0}", dateField)); } TemporalValue t = ( TemporalValue )dateField; date = t.DatePart; } else { date = DateValue.DefaultCalenderDate; } result = ZonedDateTime.of(date, time, zoneId); } else { result = defaultZonedDateTime; selectingTimeZone = false; } if (fields.containsKey(TemporalFields.Week) && !selectingDate && !selectingDateTime && !selectingEpoch) { // Be sure to be in the start of the week based year (which can be later than 1st Jan) result = result.with(IsoFields.WEEK_BASED_YEAR, safeCastIntegral(TemporalFields.Year.name(), fields.get(TemporalFields.Year), TemporalFields.Year.defaultValue)).with(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 1).with(ChronoField.DAY_OF_WEEK, 1); } result = assignAllFields(result); if (timezone != null) { if (((selectingTime || selectingDateTime) && selectingTimeZone) || selectingEpoch) { try { result = result.withZoneSameInstant(timezone()); } catch (DateTimeParseException e) { throw new InvalidValuesArgumentException(e.Message, e); } } else { result = result.withZoneSameLocal(timezone()); } } return(Datetime(result)); }
public static DateTimeValue OfEpochMillis(IntegralValue millisUTC) { return(new DateTimeValue(AssertValidArgument(() => ofInstant(ofEpochMilli(millisUTC.LongValue()), UTC)))); }
public override int CompareTo(IntegralValue other) { return(NumberValues.CompareDoubleAgainstLong(DoubleValue(), other.LongValue())); }