autorest icon indicating copy to clipboard operation
autorest copied to clipboard

Support Unix time format

Open tbombach opened this issue 10 years ago • 4 comments

AutoRest modeler supports a Unix date time format for int type. It lets a spec specify that a date needs to be sent as the number of seconds since Unix epoch time to the server. This is implemented in some languages, but requires serialization/deserialization code in some remaining languages.

This issue: https://github.com/Azure/autorest/issues/909 tracked the changes needed in the modeler. It was implemented in C# in this PR: https://github.com/Azure/autorest/pull/948

tbombach avatar Jun 03 '16 17:06 tbombach

@jianghaolu I've assigned this to you for the Java implementation, but please re-assign to someone else if they're going to end up doing this work.

tbombach avatar Jun 03 '16 17:06 tbombach

@jianghaolu there are issues with the solution when generating the code. getDateTime() method and Long class are missing:

    public DateTime created() {
        if (this.created == null) {
            return null;
        }
        return this.created.getDateTime();
    } 

    public Attributes withExpires(DateTime expires) {
        this.expires = new Long(expires);
        return this;
    } 

pomortaz avatar Jul 18 '16 16:07 pomortaz

@jianghaolu thanks for fixing the previous issue. With the new solution the issue is null pointers. For example, this will throw java.lang.NullPointerException if expires is null:

    public Attributes withExpires(DateTime expires) {
        this.expires = expires.toDateTime(DateTimeZone.UTC).getMillis() / 1000;
        return this;
    } 

pomortaz avatar Jul 18 '16 20:07 pomortaz

Fix in https://github.com/Azure/autorest/pull/1284.

jianghaolu avatar Jul 18 '16 21:07 jianghaolu