Proper parsing of String values like 1m, 1q HOUR etc

Hi,

I was wondering whether there is a proper Utility class to parse the given
values and get the duration in milliseconds probably for values such as 1m
(which means 1 minute) 1q (which means 1 quarter) etc.

I have found that elasticsearch utilizes class TimeValue but it only parses
up to week, and values such as WEEK, HOUR are not accepted. So is in
elasticsearch source any utility class that does the job ? (for Histograms,
ranges wherever is needed)

Thank you
Thomas

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/12ff6fbe-4d0e-4e8a-aa74-356311512b3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

1w means one week, 12.3d means 12.3 days, 52w means 52 weeks, 4h means 4
hours, 12.3ms means 12.3 milliseconds, 12 means 12 milliseconds but without
the suffix the value must be an integer.

In other words, TimeValue supports the parsing of a String that contains a
long integer digit string to mean milliseconds, or an integer or floating
point digit string with a suffix. So a WEEK is represented as "1w" or "7d",
and an HOUR is represented as "1h" or "60m".

So if you want to support your own vocabulary, then create a wrapper class
that converts your own terms to TimeValue strings, then then passes them
into the TimeValue class.

Brian

On Tuesday, June 17, 2014 11:31:37 AM UTC-4, Thomas wrote:

Hi,

I was wondering whether there is a proper Utility class to parse the given
values and get the duration in milliseconds probably for values such as 1m
(which means 1 minute) 1q (which means 1 quarter) etc.

I have found that elasticsearch utilizes class TimeValue but it only
parses up to week, and values such as WEEK, HOUR are not accepted. So is in
elasticsearch source any utility class that does the job ? (for Histograms,
ranges wherever is needed)

Thank you
Thomas

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/3078016f-fe47-468b-a36f-c19f2a5c607d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi Brian,

Thanks for your reply, I understand your point but if you check the source
code of TimeValue it does not support the quarter and the year so I was
wondering what is the class that supports the transformation of the string
1q into millisecods or 1y into millisecods if any

Thanks

On Tuesday, 17 June 2014 18:31:37 UTC+3, Thomas wrote:

Hi,

I was wondering whether there is a proper Utility class to parse the given
values and get the duration in milliseconds probably for values such as 1m
(which means 1 minute) 1q (which means 1 quarter) etc.

I have found that elasticsearch utilizes class TimeValue but it only
parses up to week, and values such as WEEK, HOUR are not accepted. So is in
elasticsearch source any utility class that does the job ? (for Histograms,
ranges wherever is needed)

Thank you
Thomas

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/9666f856-7327-4e97-8185-de603f02aee6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas,

The TimeValue class handles precisely defined time periods (well, pretty
much, anyway). In other words, 1s is one second. 1w is always 7d (leap
seconds notwithstanding, but that doesn't really affect the precision).

But what is one year? 365 days? 365.25 days? 366 days in a leap year?

What is one quarter? Exactly 91.25d (which is 365 / 4)? Or 3 months?

But then, what is a month? 28 days? 31 days? Use 28d or 31d if that's what
you mean; 1 month has no deterministic meaning all by itself. And 1 quarter
is 3 months but without any deterministic way to convert to a precise
number of milliseconds.

The TimeValue class has no support for locale nor day of year nor leap year
nor days in a month. It's best to use Joda time if you wish to perform
proper year-oriented calculations. And it will return milliseconds
precision if you wish, which will plug directly back into a TimeValue.

Brian

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/05798106-2a3d-4b7a-8a06-572116e0694b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi,

Thanks again for your time, what I'm trying to do is to be able to generate
for example the time in milliseconds in the same way the elasticsearch core
does when for example you passes into the date histogram the 1q
configuration. I'm trying to simulate in a way the interval of date
histogram without using the date histogram, if possible. What is the one
liner of code (if you can say that) that does this transformation of 1q
into milliseconds and elasticsearch is able to give the intervals of date
histogram, because then i compare time intervals with date histogram and I
want to be exactly the same.

And please allow me to make one more question, since elasticsearch uses
joda start of week is considered always Monday? independently of the
timezone?

Thanks!!

Thomas

On Tuesday, 17 June 2014 18:31:37 UTC+3, Thomas wrote:

Hi,

I was wondering whether there is a proper Utility class to parse the given
values and get the duration in milliseconds probably for values such as 1m
(which means 1 minute) 1q (which means 1 quarter) etc.

I have found that elasticsearch utilizes class TimeValue but it only
parses up to week, and values such as WEEK, HOUR are not accepted. So is in
elasticsearch source any utility class that does the job ? (for Histograms,
ranges wherever is needed)

Thank you
Thomas

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/bbff2784-c06d-4944-9887-0147e9e31a5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.