# setSeconds odd behavior

**URL:** <https://forum.inductiveautomation.com/t/setseconds-odd-behavior/64021>\
**Category:** Ignition\
**Tags:** ignition81, vision, scripting\
**Created:** [September 13, 2022, 4:27pm UTC](https://forum.inductiveautomation.com/t/setseconds-odd-behavior/64021 "2022-09-13T16:27:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ricardo.ortolani](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@ricardo.ortolani](https://forum.inductiveautomation.com/u/ricardo.ortolani)\
**Post date:** [September 13, 2022, 4:27pm UTC](https://forum.inductiveautomation.com/t/setseconds-odd-behavior/64021/1 "2022-09-13T16:27:00Z")

</div>

I found an odd behavior when using setSeconds.

to explain better, I create a new window:  
drop two components:

- popup calendar
- button

In the button, I added the following script

```auto
sDateTime = event.source.parent.getComponent('Popup Calendar').date
tDateTime = event.source.parent.getComponent('Popup Calendar').date

print sDateTime, type(sDateTime), sDateTime.getTime()
print tDateTime, type(tDateTime), tDateTime.getTime()

tDateTime.setSeconds(tDateTime.getSeconds()+1)
print "tDateTime:", tDateTime

```

Basic I assign the [Popup Calendar] date to two variables [sDateTime and tDateTime]

I added 1 second to the variable [tDateTime], but when I do that it also add 1 second to the Popup Calendar date.

So I am trying to understand this behavior, since this works fine in the script console, but when I use in the button, it keep changing the popup calendar value, which doesn;t make any sense since I am assigning the popup calendar value to a variable, and I am changing the variables.

if anyone has any inside or ideas on this please let me know.

thanks,

---

<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:** [September 13, 2022, 4:32pm UTC](https://forum.inductiveautomation.com/t/setseconds-odd-behavior/64021/2 "2022-09-13T16:32:23Z")

</div>

This is expected behavior.  
The JVM (and thus, both Java and Jython) pass non-primitive values by reference.  
So `tDateTime` is defined as ‘the date object attached to the popup calendar’. When you mutate that date _instance_, you’re manipulating the single object in memory that’s shared between your executing script and the popup calendar component.

If you want a unique instance, you need to create your own Date object. The easiest way to do this would be to convert the original object into its milliseconds-from-epoch representation, then create a new object from that:

```auto
tDateTime = system.date.fromMillis(system.date.toMillis(event.source.parent.getComponent('Popup Calendar').date))

```

---

<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:** [September 13, 2022, 4:54pm UTC](https://forum.inductiveautomation.com/t/setseconds-odd-behavior/64021/3 "2022-09-13T16:54:04Z")

</div>

I guess I lied a bit - the _easiest_ way would probably be to call `clone()` on the instance, which returns a new object:

```python
now = system.date.now()
print now, id(now)
now2 = now.clone()
print now2, id(now2)

now.setSeconds(1)
print now, id(now)
print now2, id(now2)

```

```auto
>>> 
Tue Sep 13 09:52:16 PDT 2022 4
Tue Sep 13 09:52:16 PDT 2022 5
Tue Sep 13 09:52:01 PDT 2022 4
Tue Sep 13 09:52:16 PDT 2022 5

```

However, `clone` is a bit weird and won’t work on most object types, so I’d probably still just pass to/from milliseconds in this case.
