I've included the whole method below, but really the challenge is simulating DateTime.MaxValue.Ticks in Java 8. I also don't know the equivalent of ".ToString("D19") in Java.
I thought I had figured out how to begin, which was by using Instant.MAX.toEpochMilli(), which I could then multiply by 10000 to get Ticks. Sadly, this simple statement throws an exception, so it's a non-starter:
Caught: java.lang.ArithmeticException: long overflow
Here is the original method. It's used to query Azure Storage Tables for historical metrics.
// Creates a TableQuery for getting metrics by timestamp
private static TableQuery GenerateMetricTimestampQuery(string partitionKey, DateTime startTime, DateTime endTime)
{
return GenerateMetricQuery(
partitionKey,
(DateTime.MaxValue.Ticks - endTime.Ticks + 1).ToString("D19") + "__",
(DateTime.MaxValue.Ticks - startTime.Ticks).ToString("D19") + "__");
}
Here is an example of a RowKey field value:
2519303419199999999__
I've spent a day on this and I'm pretty stumped. Any help would be greatly appreciated.
If possible, I would prefer to do this without JodaTime.
UPDATE1*** Based on a comment, here is an example of the exception in Java.
import java.time.Instant;
public class Tester {
public static void main(String[] args){
System.out.println(Instant.MAX.toEpochMilli());
}
}