I'm setting a due date on an issue, which is now stored as a numeric string. For instance, setting a due date to December 19, 2018 on an issue gives me "17884" when reading the DocumentConstants.ISSUE_DUEDATE field of that issue from the index. How do I convert that string/number back to a Date?
Quick question, where are you getting the date string from? I ask because In the Lucene index itself, dates are now being stored as longs.
But you're right on the money with the offset; we store due dates as the number of days since the unix/java epoch on Jan. 1st, 1970. Also, if you're able to make use of Java's new Date/Time api,
makes the conversion a little easier.
Just a word of caution: for other Jira fields that capture both a date and a time, the number stored in the Lucene index is the number of milliseconds since midnight on the epoch.
Thanks for your reply @Seth Utecht!
We're getting string values because we're reading them from the index using e.g.
which returns an array of Strings. So a date value read that way is in fact a Long represented as a String (e.g. "17884").
Thanks for confirming our assumption about the date representation! We also noticed what you mentioned about date and time values (like the `resolutiondate` field for instance) being formatted as a number of milliseconds. Does the jira api provide some utility method to safely parse a date OR date and time to a Date without the code having to know what's actually stored in a given index field? Though we could just as well implement this by guessing based on the Long value length...
"JIRA stores dates in Lucene as the number of seconds since the Epoch (1 January 1970) in Lucene long prefix-coded format." so you can either:
String lucenePrefixedCoded = document.get(DocumentConstants.ISSUE_CREATED);
long secondsSinceEpoch = NumericUtils.prefixCodedToLong(lucenePrefixedCoded);
Date created = new Date(secondsSinceEpoch * 1000);
or the shortcut:
Date created = LuceneUtils.stringToDate(document.get(DocumentConstants.ISSUE_CREATED));
Introducing Jira Cloud for Excel Here at the product integrations team at Atlassian, we are thrilled to announce the new Jira Cloud for Excel add-in! This add-in lets you export Jira data directly ...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events