# Ad-hoc Trends error when selecting duration of a month or more

**URL:** <https://forum.inductiveautomation.com/t/ad-hoc-trends-error-when-selecting-duration-of-a-month-or-more/31379>\
**Category:** Ignition\
**Created:** [January 17, 2020, 6:54pm UTC](https://forum.inductiveautomation.com/t/ad-hoc-trends-error-when-selecting-duration-of-a-month-or-more/31379 "2020-01-17T18:54:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpavlicek](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rpavlicek/32/55868_2.png) [@rpavlicek](https://forum.inductiveautomation.com/u/rpavlicek)\
**Post date:** [January 17, 2020, 6:54pm UTC](https://forum.inductiveautomation.com/t/ad-hoc-trends-error-when-selecting-duration-of-a-month-or-more/31379/1 "2020-01-17T18:54:41Z")

</div>

We are using the Ad-hoc trends template in our vision project. It’s working great except we get an error in the duration component when we select a time of 1 month or larger. The error is in the script at the cal.add syntax:

File “event:propertyChange”, line 13, in   
TypeError: add(): 2nd arg can’t be coerced to int

**Code:**

from java.util import Calendar  
from java.util import Date

if event.propertyName == “selectedValue”:  
seconds = long(event.newValue)

```
if seconds > 0:
	cal = Calendar.getInstance()
	chart = event.source.parent.getComponent('Easy Chart')
	
	endDate = Date()
	cal.setTime(endDate)
	cal.add(Calendar.MILLISECOND, seconds * -1000)
	startDate = cal.getTime()
	
	chart.endDate = endDate
	chart.startDate = startDate
```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 17, 2020, 7:09pm UTC](https://forum.inductiveautomation.com/t/ad-hoc-trends-error-when-selecting-duration-of-a-month-or-more/31379/2 "2020-01-17T19:09:43Z")

</div>

> [@rpavlicek](#):
>
> `cal.add(Calendar.MILLISECOND, seconds * -1000)`

The Calendar class' [`add`](https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#add(int,%20int)) method only accepts a (32-bit) integer value, so 1 month in milliseconds (2,592,000,000) overflows INT\_MAX (2,147,483,647).

If you don't need millisecond precision, you can easily change the math (and use `Calendar.SECOND`) instead, and you'll still be fine for time ranges up to ~68 years 🙂

---

<div class="post-metadata">

**Author:** ![rpavlicek](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rpavlicek/32/55868_2.png) [@rpavlicek](https://forum.inductiveautomation.com/u/rpavlicek)\
**Post date:** [January 18, 2020, 2:37am UTC](https://forum.inductiveautomation.com/t/ad-hoc-trends-error-when-selecting-duration-of-a-month-or-more/31379/3 "2020-01-18T02:37:50Z")

</div>

Thanks, we were on the right track. We tried this before, but realized that we needed to multiple the “seconds” variable in the 2nd argument by -1 to go back in time.
