formatDateTime issue?


#1

Recently noticed a piston misbehaving and eventually seemed to find the issue maybe. This only recently started happening, as in the last week or maybe two. Pulling the data from a device shows the correct data, but after using formatDateTime, it’s off by a day as seen in attached images.


#2

It would be good to show what the device attribute is from the HE console -> devices -> the Device


#3

It’s a Google calendar entry pulled from a calendar that shows my trash and recycling pickup schedule.


#4

Could it be a discrepancy be between the date formats being used by HE & google?
Could google be my-dd-yyyy & HE do-mm-yyyy


#5

Maybe, but it’s worked fine for like 2 years and just recently started to be wrong. So something changed somewhere


#6

Is the driver that is doing this posted somewhere?


#7

Yes, but I’m not sure it is the driver. The driver is merely polling the info from a Google calendar. The attribute is populated with the correct date, it’s webcore that is producing the wrong output when formatting the data from this attribute now. At least it seems that way to me.

There are 2 app codes and 2 driver codes for the Google calendar integration. All are at the following link but I’ll directly link each as well after the main link.

Main app GitHub page

2 app codes
App 1
App 2

2 driver codes
Driver 1
Driver 2

It is also available through habitat package manager by searching for keyword Google calendar.


#8

I’ve just had a play with the formatdatetime function, and it’s either not working or not working as expected.
E.g {formatDateTime(“11-12-2023”,“MMMMM d”)} returns “October 11”

Looking at the documentation, the first parameter should be type datetime, so I’m not sure if the google calendar string value is being cast correctly. That doesn’t explain why it used to work though,

It may be worth trying to set the calendar date/time into a WC datetime variable, and when that’s correct, use the variable in function.


#9

There may be an issue.

The time in the driver is a string, and the string is not specifying a timezone.

So webcore parses the string to a time (and should assume a timezone and time), and then later needs to convert that time back to a string with a timezone. So I’ll look more now that I understand what the driver is giving to webcore, if the problem is the parse a string side, or convert a datetime to a local time string

The simple reproducer piston makes this easier for me vs. me having to create a reproducer piston.


#10

I was just trying to create a reproducer piston and notice that WC will not let you set a data time variable to a string variable (the string variables are nor shown in the selection box)

So I guess WC does not cast these data types.


#11

It does, just use an expression.

Here is my test program, it is working… (are you up to date with webcore?)

11%20PM


#12

Yes, I’m up to date.

  • You cant set a datetime variable to the value of a string variable (holding a valid datetime value)
  • I think the OP issue is that the date values from google are mm-dd-yyyy hh:mm:as am/pm which dont seem to convert correctly into a datetime variable

#13

so give me a small example piston of the failure


#14

This shows the OP problem.
If you edit and add a line to set variable eventdate, then set it to a variable, the only variable available is eventdate


#16

I’m not clear from your device why you are parsing the date only.

Can you show the original piston that is doing this?

One could argue a bug, but I don’t see that webCoRE ever parsed a date string as you are showing (ie not a recent change at least in webCoRE)

datetime parsing in HE is different than ST, ie I have added a lot of code to parse date and time strings, and this format has not been added.

I can look at adding it, but it would be good to see what your piston is doing as it may be easier to adjust that.


#17

So a workaround is

10%20PM


#18

Long story short, I’m monitoring the calendar that has trash and recycling pickup dates.

The main piston using these sets a tile on my WC dashboard. The piston will see if the next pickup is the next day and set the tile to alert me pickup is the next day. If pickup is the current day the tile will show it’s today and if it’s neither, it’ll display the date that the next pickup is.

I also have a piston that runs when I arrive home that sends a push notification if either trash or recycling or both need to go out.

First snapshot is tile updating piston second is for me arriving home.


#19

Where can I find the syntax for parseDateTime? It doesn’t seem to be documented anywhere for webcore.


#20

This function is calling SimpleDateFormat with the 2nd argument for the expected format.

https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/text/SimpleDateFormat.html


#21

Pardon my nativity, but are there a lot of “undocumented” but supported arguments and such?