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

**URL:** <https://discuss.elastic.co/t/proper-parsing-of-string-values-like-1m-1q-hour-etc/18159>\
**Category:** Elasticsearch\
**Created:** [June 17, 2014, 3:31pm UTC](https://discuss.elastic.co/t/proper-parsing-of-string-values-like-1m-1q-hour-etc/18159 "2014-06-17T15:31:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Bolis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_bolis/32/700_2.png) [@Thomas\_Bolis](https://discuss.elastic.co/u/Thomas_Bolis)\
**Post date:** [June 17, 2014, 3:31pm UTC](https://discuss.elastic.co/t/proper-parsing-of-string-values-like-1m-1q-hour-etc/18159/1 "2014-06-17T15:31:37Z")

</div>

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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/12ff6fbe-4d0e-4e8a-aa74-356311512b3e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [June 23, 2014, 7:48pm UTC](https://discuss.elastic.co/t/proper-parsing-of-string-values-like-1m-1q-hour-etc/18159/2 "2014-06-23T19:48:28Z")

</div>

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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/3078016f-fe47-468b-a36f-c19f2a5c607d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Thomas\_Bolis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_bolis/32/700_2.png) [@Thomas\_Bolis](https://discuss.elastic.co/u/Thomas_Bolis)\
**Post date:** [June 24, 2014, 7:57am UTC](https://discuss.elastic.co/t/proper-parsing-of-string-values-like-1m-1q-hour-etc/18159/3 "2014-06-24T07:57:10Z")

</div>

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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/9666f856-7327-4e97-8185-de603f02aee6%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [June 24, 2014, 9:34pm UTC](https://discuss.elastic.co/t/proper-parsing-of-string-values-like-1m-1q-hour-etc/18159/4 "2014-06-24T21:34:01Z")

</div>

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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/05798106-2a3d-4b7a-8a06-572116e0694b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Thomas\_Bolis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_bolis/32/700_2.png) [@Thomas\_Bolis](https://discuss.elastic.co/u/Thomas_Bolis)\
**Post date:** [June 25, 2014, 7:54am UTC](https://discuss.elastic.co/t/proper-parsing-of-string-values-like-1m-1q-hour-etc/18159/5 "2014-06-25T07:54:50Z")

</div>

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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/bbff2784-c06d-4944-9887-0147e9e31a5e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:19am UTC](https://discuss.elastic.co/t/proper-parsing-of-string-values-like-1m-1q-hour-etc/18159/6 "2017-07-06T01:19:56Z")

</div>


