ion-python
ion-python copied to clipboard
C extension timestamp precision defaults to 6 while sometimes people wants other precision
The issue was raised in https://github.com/amzn/ion-python/issues/208
Consider
obj = simple_types.IonPyTimestamp.fromisoformat("2022-07-01")
str = simpleion.dumps(obj)
What should be the expected str
value? It's 2022-07-01T00:00:00.000000-00:00
currently as C extension set precision to 6 by default but users may only want 2022-07-01
.
We should implement https://github.com/amzn/ion-python/issues/208#issuecomment-1190819593 solution 3 and support constructing an ion timestamp by fromisoformat
. Here is a proof-of-concept - https://github.com/amzn/ion-python/issues/208#issuecomment-1192011182
Just to be clear, there are two different problems here, and neither one is specific to the C extension.
-
Timestamp
(and therefore alsoIonPyTimestamp
) can have a precision ofNone
. It is possible to create a Timestamp with a precision ofNone
even though it may appear to the user that the precision should be implied. (E.g. inTimestamp(2022, 8, 1)
it looks like the precision should beday
.) When precision isNone
all of the writer implementations must choose some sort of default precision, and whatever that default may be (even if it is user configurable), it is likely to be surprising to users because users will expect thatTimestamp
constructor and factory functions can infer the correct precision when the precision seems obvious. -
ion-python
writers have to be able to handle writing standard types likedate
anddatetime
as Ion. Since these types do not have a notion of precision like Ion Timestamps, the writer implementations are forced to choose a default precision. Some users may want to configure the default precision used by a writer. This can probably be solved by adding adefault_timestamp_precision
to thekwargs
ofsimpleion.dumps()
.