Skip to content

Dates, datetime and timestamps are not allowed before 1.1.1970 #13

@planesweep

Description

@planesweep

Problem

The ydb-java-sdk does not allow to store a date, datetime or timestamp before 1.1.1970. In my opinion this does NOT make any sense. How do you suppose to store a birthdate before 1.1.1970.

How to reproduce

  1. Create a customer table
        TableDescription customerTable = TableDescription.newBuilder()
                .addNullableColumn("email", PrimitiveType.utf8())
                .addNullableColumn("firstname", PrimitiveType.utf8())
                .addNullableColumn("lastname", PrimitiveType.utf8())
                .addNullableColumn("birthdate", PrimitiveType.date())
                .addNullableColumn("modifier", PrimitiveType.utf8())
                .addNullableColumn("lastupdate", PrimitiveType.timestamp())
                .setPrimaryKey("email")
                .build();
  1. Store a birthdate before 1.1.1970 -> save birthdate 1.1.1930

  2. Finally you get this exception

Exception in thread "main" java.lang.IllegalArgumentException: negative daysSinceEpoch: -354285
	at com.yandex.ydb.table.values.PrimitiveValue.date(PrimitiveValue.java:205)
	at com.yandex.ydb.table.values.PrimitiveValue.date(PrimitiveValue.java:215)
	at com.yandex.ydb.examples.simple.BenchmarkDatabase.addDataToCustomerTable(BenchmarkDatabase.java:172)
	at com.yandex.ydb.examples.simple.BenchmarkDatabase.fillData(BenchmarkDatabase.java:157)

Issue (weird restriction of negative days since Epoch)

Please check PrimitiveValue.java https://github.com/yandex-cloud/ydb-java-sdk/blob/master/table/src/main/java/com/yandex/ydb/table/values/PrimitiveValue.java

   public static PrimitiveValue date(long daysSinceEpoch) {
        if (daysSinceEpoch < 0) {
            throw new IllegalArgumentException("negative daysSinceEpoch: " + daysSinceEpoch);
        }
        return new InstantValue(PrimitiveType.date(), TimeUnit.DAYS.toMicros(daysSinceEpoch));
    }

    public static PrimitiveValue date(LocalDate value) {
        return date(value.toEpochDay());
    }

    public static PrimitiveValue date(Instant value) {
        return date(TimeUnit.SECONDS.toDays(value.getEpochSecond()));
    }

All dates are finally converted into a long but a negative long is not allowed, why?
Linux and Java can handle date before the epoch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions