-
Notifications
You must be signed in to change notification settings - Fork 96
Description
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.