Scheduled Gateway Script operation during Daylight Savings time shift

I have a gateway script scheduled to execute 1 minute past the hour, every hour which syncs the PLC clocks with the gateway clock.

In September the clocks jump forward an hour from 2AM to 3AM

In the gateway logs I have observed is the following:

01:01 - Script executes, no update to clocks preformed
03:01 - Script executes, no update to clocks preformed
04:01 - Script executes, PLC clocks updated

My expectation is that when the system time jumps to 3AM and the script is then executed at 3:01AM the times should be updated then, However this doesn’t appear to be the case.

I use system.date.now() to retrieve the gateway time in my script, is there anything else I should be calling to ensure the system time I retrieve is correct?

What do you do after this? How do you pick it apart and then sync the time to the PLC clock?

	#-------------
	# Get Gateways time
	#-------------
	GatewayDateTime=system.date.now()
	
	for TargetPLC in TargetPLCList:		
		try:		
			#-------------
			# Get PLC time
			#-------------
			PathPLCYear=Path+"/"+TargetPLC+"/RTC/Year"
			PathPLCMonth=Path+"/"+TargetPLC+"/RTC/Month"
			PathPLCDay=Path+"/"+TargetPLC+"/RTC/Day"
			PathPLCHour=Path+"/"+TargetPLC+"/RTC/Hour"
			PathPLCMinute=Path+"/"+TargetPLC+"/RTC/Minute"
			PathPLCSecond=Path+"/"+TargetPLC+"/RTC/Second"
			PathPLCSet=Path+"/"+TargetPLC+"/RTC/Set"
			PathPLCTags=[PathPLCYear,PathPLCMonth,PathPLCDay,PathPLCHour,PathPLCMinute,PathPLCSecond,PathPLCSet]
			PLCYear,PLCMonth,PLCDay,PLCHour,PLCMinute,PLCSecond,PLCSet = [x.value for x in system.tag.readBlocking(PathPLCTags)]
			
			#-------------
			#Convert to Date datatype
			#-------------
			PLCDateTime=system.date.parse(str(PLCDay)+"-"+str(PLCMonth)+"-"+str(PLCYear)+" "+str(PLCHour)+":"+str(PLCMinute)+":"+str(PLCSecond), 'dd-MM-yyyy HH:mm:ss')		
			
			#-------------
			# Compare PLC Time to Gateway Time
			#-------------
			MinutesDifference=system.date.minutesBetween(GatewayDateTime,PLCDateTime)
			Logger.info(str(TargetPLC)+" "+str(MinutesDifference)+" minute(s) differential with gateway")
			#-------------
			# If the allowable difference is exceeded, update the PLC time to the gateway time
			#-------------
			if abs(MinutesDifference) > AllowableDifference:
				GatewayYear=system.date.getYear(GatewayDateTime)
				GatewayMonth=system.date.getMonth(GatewayDateTime)+1
				GatewayDay=system.date.getDayOfMonth(GatewayDateTime)
				GatewayHour=system.date.getHour24(GatewayDateTime)
				GatewayMinute=system.date.getMinute(GatewayDateTime)
				GatewaySecond=system.date.getSecond(GatewayDateTime)
				PLCSet = 1
				system.tag.writeBlocking(PathPLCTags, [GatewayYear,GatewayMonth,GatewayDay,GatewayHour,GatewayMinute,GatewaySecond,PLCSet])
				Logger.info(str(TargetPLC)+" time synced with gateway")
		except:
			Logger.info(str(TargetPLC)+" failed to communicate")
			continue

18467b0a1e4bdd233f289f8fa1d015ff95f25d30_2_690x69

image

image

For better readability, wrap your code in a code block tag, it makes it much easier to read.

1 Like

updated with actual code rather than pseudocode

1 Like

I’ve added the Gateway time as part of the log message so will monitor next year to peak behind the scenes

I think at 03:01 your PLC ‘hour’ would be 2 and your gateway ‘hour’ would be 3?

On my gateway (Pacific/Auckland time zone) if I run

system.date.setTime(system.date.getDate(2025, 8, 28), 2, 1, 0)
system.date.setTime(system.date.getDate(2025, 8, 28), 3, 1, 0)

Then I see

Sun Sep 28 03:01:00 NZDT 2025
Sun Sep 28 03:01:00 NZDT 2025

I guess the Java date / time library is clever enough to know that 2025-09-28 02:01:00 isn’t a ‘valid’ time and adjusts accordingly to the right offset.

It looks like your code will observe the same behaviour

Screenshot 2025-10-02 164514

Only at 04:01 will we see two different times

1 Like

If your PLC doesn't have proper timezone support, the Right Answer™ is to run the PLC clock in UTC all the time. Use java's ZonedDateTime to retrieve the current time at UTC and write its components to the PLC.

I had been going down the route of configuring NTP, Time zone and DLS on all our PLCs. However, I found there are a handful which don’t support these.

So my preference is rather than having various time keeping systems in place depending on what model the PLC happens to be, is to have one unified system.

Suffice to say… back to the drawing board, I’ll consider your suggestion

Thanks

Thanks! that is exactly the issue.
here I was thinking I was being smart utilizing the built in tools. turns out the tools are smarter than I am!