You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Kalle Niemitalo (Jira)" <ji...@apache.org> on 2022/06/21 07:21:00 UTC

[jira] [Commented] (AVRO-3078) C#: Logical type 'local-timestamp-millis'

    [ https://issues.apache.org/jira/browse/AVRO-3078?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17556692#comment-17556692 ] 

Kalle Niemitalo commented on AVRO-3078:
---------------------------------------

As I wrote in [https://github.com/apache/avro/pull/1628#discussion_r868952116], I don't believe the implementation is correct. It converts from UTC to local time or back. These conversions depend on the local time of the computer on which the software is used, and they are different from what the Java implementation does. The tests that were added in the pull request do not detect this error because they convert from DateTime to Int64 and back, and the errors in these conversions cancel each other.

Instead of using DateTime.ToUniversalTime(), ConvertToBaseValue should ignore the DateTime.Kind and encode the date and time without time zone conversions.

Instead of using DateTime.ToLocalTime(), ConvertToLogicalValue should keep the date and time unchanged and set DateTimeKind.Unspecified. That would be better than DateTimeKind.Local because we can use these logical types in a record that has the UTC offset or time zone identifier in a separate field. DateTimeKind.Local implies that the time zone is TimeZoneInfo.Local, but the Avro specification says that these logical types use "a local timezone", which might not be the same time zone as TimeZoneInfo.Local.

There should be a test that converts a DateTime to an Int64 or vice versa, and checks that the result matches what the Java code would produce.

> C#: Logical type 'local-timestamp-millis'
> -----------------------------------------
>
>                 Key: AVRO-3078
>                 URL: https://issues.apache.org/jira/browse/AVRO-3078
>             Project: Apache Avro
>          Issue Type: Improvement
>          Components: csharp
>    Affects Versions: 1.10.2
>            Reporter: Vladimir Kralik
>            Assignee: Zoltan Csizmadia
>            Priority: Critical
>              Labels: pull-request-available
>             Fix For: 1.11.1, 1.12.0
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> * *as* a programmer
>  * *i want* to add support for logical type {{local-timestamp-millis}} for C# code generation
>  * *because* {{avrogen}} fails with 
> {code:bash}
> > dotnet tool install --global Apache.Avro.Tools --version 1.10.2
> > dotnet tool restore
> Tool 'apache.avro.tools' (version '1.10.2') was restored. Available commands: avrogen
> > dotnet avrogen -p ../thymus.avpr outdir
> Exception occurred. Logical type 'local-timestamp-millis' is not supported.
> {code}
> {code:java}
> {
>   "protocol" : "ThymusProtocol",
>   "namespace" : "model.thymus",
>   "types" : [ {
>        "type" : "record",
>         "name" : "TMVyk",
>         "namespace" : "model.thymus",
>         "fields" : [{
>               "name" : "cas",
>               "type" : {
>                   "type" : "long",
>                   "logicalType" : "local-timestamp-millis"
>               }
>             }]
>    } ],
>   "messages" : { }
> } 
> {code}



--
This message was sent by Atlassian Jira
(v8.20.7#820007)