Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - DONT MERGE - Issue/timestmap issue reproducer #991

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/main/java/net/openhft/chronicle/wire/TimestampReproducer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.openhft.chronicle.wire;

import net.openhft.chronicle.wire.ServicesTimestampLongConverter;

public class TimestampReproducer {
public static void main(String[] args) {
// Print out the configured time unit.
System.out.println("Configured time unit: " + ServicesTimestampLongConverter.timeUnit());

String isoTimestamp = "2025-03-04T09:58:14.201392128";
long parsedIso = ServicesTimestampLongConverter.INSTANCE.parse(isoTimestamp);
System.out.println("Parsed ISO timestamp: " + parsedIso + " (" + formatTimestamp(parsedIso) + ")");

// Example 2: A full numeric timestamp as seen before.
String numericTimestamp = "201392128";
long parsedNumeric = ServicesTimestampLongConverter.INSTANCE.parse(numericTimestamp);
System.out.println("Parsed full numeric timestamp: " + parsedNumeric + " (" + formatTimestamp(parsedNumeric) + ")");

// Example 3: A truncated numeric timestamp (simulating missing leading zeros).
String truncatedTimestamp = "201392";
long parsedTruncated = ServicesTimestampLongConverter.INSTANCE.parse(truncatedTimestamp);
System.out.println("Parsed truncated numeric timestamp: " + parsedTruncated + " (" + formatTimestamp(parsedTruncated) + ")");
}

/**
* Helper method to convert the parsed timestamp (in the configured time unit) to a human-readable date.
* This example assumes that the configured unit is nanoseconds.
*/
private static String formatTimestamp(long timestamp) {
long millis = timestamp;
if (ServicesTimestampLongConverter.timeUnit().equals(java.util.concurrent.TimeUnit.NANOSECONDS)) {
millis = timestamp / 1_000_000;
} else if (ServicesTimestampLongConverter.timeUnit().equals(java.util.concurrent.TimeUnit.MICROSECONDS)) {
millis = timestamp / 1_000;
}
return new java.util.Date(millis).toString();
}
}