Skip to content

Allow "DateTimeKind.Local" as TimeStamp #441

@hexxone

Description

@hexxone

Proposal:
Make it possible to use DateTimeKind.Local for TimeStamps by removing the check or adding an extra option.

Current behavior:
When manually calculating a TimeStamp to be inserted the DateTimeKind flag is automaticaclly set to Local.
This may be required, because the Data origin is in a different Time-Zone relative to us.
e.g.:

var localOffset = startTime + TimeSpan.FromHours(source.Offset)

Using this as a TimeStamp then casues an Exception:

The unhandled exception occurs: System.ArgumentException: Timestamps must be specified as UTC (Parameter 'timestamp')
   at InfluxDB.Client.Writes.PointData.Timestamp(DateTime timestamp, WritePrecision timeUnit)
   at InfluxDB.Client.Internal.MeasurementMapper.ToPoint[TM](TM measurement, WritePrecision precision)
   at InfluxDB.Client.BatchWriteMeasurement`1.ToLineProtocol()
   at InfluxDB.Client.WriteApi.<>c.<.ctor>b__9_9(StringBuilder builder, BatchWriteData batchWrite)

Desired behavior:
Remove the check for DateTimeKind or give the possibility to explicitly disable it using Options?

Relevant line: https://github.com/influxdata/influxdb-client-csharp/blob/master/Client/Writes/PointData.cs#L255

Alternatives considered:
The current alternative is manually setting the flag, using:

var localUtcTime = DateTime.SpecifyKind(localOffset, DateTimeKind.Utc);

However, doing so is essentially unnecessary, if it functionally doesn't make a difference in the end.

Developers should know what kind of data they are working with in their respective context.
If they want to insert "locally" calculated DateTime's, why would it be as restrictive to throw an Error by default?

Use case:
If you have many different sources where a DateTime can get inserted from,
checking all these cases and doing an extra "call" can become rather annoying.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy