langfuse-java icon indicating copy to clipboard operation
langfuse-java copied to clipboard

Error when Using Time like 00:00:00

Open yangyaofei opened this issue 5 months ago • 3 comments

In here

https://github.com/langfuse/langfuse-java/blob/78b8673f4f17d8ca1de22abde5942dbd441607a3/src/main/java/com/langfuse/client/resources/sessions/SessionsClient.java#L64-L70

The Timestamp using OffsetDatetime::toString, when the time like: 1900-01-01T00:00:00.000

toString will get 1900-01-01T00:00 (shorter) which will make langfuse server return error.

yangyaofei avatar Aug 06 '25 09:08 yangyaofei

@yangyaofei Do you have an intuitive idea on how this could be patched? Are there utility methods in Java that convert this to a valid ISO String?

Steffen911 avatar Oct 27 '25 08:10 Steffen911

@Steffen911 Use DateTimeFormatter

public static void main(String[] args) {
    OffsetDateTime odt = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneOffset.ofHours(8));
    String isoString = odt.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
    System.out.println(isoString);
    System.out.println(odt.toString());
}

2000-01-01T00:00:00+08:00
2000-01-01T00:00+08:00

And if 2000-01-01T00:00+08:00 still got error, use formatter like offsetDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX"))

yangyaofei avatar Oct 27 '25 13:10 yangyaofei

This is the doc for toStirng function:

Outputs this date-time as a String, such as 2007-12-03T10:15:30+01:00.
The output will be one of the following ISO-8601 formats:
uuuu-MM-dd'T'HH:mmXXXXX
uuuu-MM-dd'T'HH:mm:ssXXXXX
uuuu-MM-dd'T'HH:mm:ss.SSSXXXXX
uuuu-MM-dd'T'HH:mm:ss.SSSSSSXXXXX
uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSSXXXXX
The format used will be the shortest that outputs the full value of the time where the omitted parts are implied to be zero.

So, all the format are ISO-8601 format.

There's some gap between python and java. 😂😂😂😂

yangyaofei avatar Oct 27 '25 13:10 yangyaofei