Timezone, date picker problem

So database is in the cloud, in UTC timestamp.
Gateway is also in the cloud, with UTC timezone.
Whoever created the project, also configured to be UTC timezone.

The End User in on EST timezone.

I have records in database that I want to filter by datetime.

The date picker is headache. Biggest headache of all time up to date.

The date picker UI shows UTC.
BUT date picker value is EST.

I have not sort the Ask,
But essentially, I need to create a wrapper for date picker, so I can intialized it and also returns desired output timezone.

(1) first question:
How can I get offset of EST? that will work all year round?
right now, i get offset from session-device-offset. I want it to be independent of device timezone.

(2) this is where I need to learn java date object, system.date is acting strange.
In perspective, system.date.now() returns EST. cool!
system.date.Midnight() and system.date.setTime() return UTC

Start here, follow links:

1 Like

For record, education. Below is what I did. Please feel free to comment.

Again, gateway and project is on UTC timezone.
But date picker is in Browser timezone.

When I initialized date picker using system.date.now() (which is in UTC), it doesn't work.
I need to spoof it:

	def convert_utc_to_browser_time(date, timezoneId):
		from java.time import Instant, ZoneId
		date_string = system.date.format(date, "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
		offset_min = ZoneId.of(timezoneId).getRules().getOffset(Instant.parse(date_string)).getTotalSeconds() // 60
		return system.date.addMinutes(date, offset_min)

	# usage
	params['initBrowserDatetime'] 	= convert_utc_to_browser_time(system.date.now(), self.session.props.device.timezone.id)

The result of date picker convert it back to UTC.
Like so:

	def convert_browser_time_to_utc(date, timezoneId):
		from java.time import Instant, ZoneId
		date_string = system.date.format(date, "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
		offset_min = ZoneId.of(timezoneId).getRules().getOffset(Instant.parse(date_string)).getTotalSeconds() // 60
		return system.date.addMinutes(date, offset_min*-1)

	if "java.util.Date" in str(type(currentValue.value)):		
		browser_tz	 = self.session.props.device.timezone.id
		browser_date = currentValue.value
		
		utc_date = convert_browser_time_to_utc(browser_date, browser_tz)

if Gateway happen to be in different timezone, I don't know if the above still works.

Another realization.
Dates shown in custom property are browser offsets:

Appreciate for any thoughts.

Interrestingly, my convert to utc midnight does not work on the daylight saving day March 8.

I use this function to get Est Midnight (in UTC):

	def convert_utc_to_est_midnight_inUtc(utc_date):
		from java.text import SimpleDateFormat
		from java.util import TimeZone, Calendar
		utc_string = system.date.format(utc_date, "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
		parser = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
		parser.setTimeZone(TimeZone.getTimeZone("UTC"))
		utcDate = parser.parse(utc_string)
		est_tz = TimeZone.getTimeZone("America/New_York")
		cal = Calendar.getInstance(est_tz)
		cal.setTime(utcDate)
		# set midnight in est
		cal.set(Calendar.HOUR_OF_DAY, 0)
		cal.set(Calendar.MINUTE, 0)
		cal.set(Calendar.SECOND, 0)
		cal.set(Calendar.MILLISECOND, 0)
		
		estMidnight_utc = cal.getTime()
		return estMidnight_utc

1am in date picker should return 5am UTC.
5am in date picker should return 4am UTC.

Edit.
On Second thought, I think it is correct.
Midnight is Midnight.