Skip to content

Blockly ZoneDateTime with zero Milli / Micro / Nano operations fails #3188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Little-Hobo opened this issue May 10, 2025 · 1 comment
Open
Labels
bug Something isn't working main ui Main UI

Comments

@Little-Hobo
Copy link

Little-Hobo commented May 10, 2025

When using Blockly to try to create a datetime object at exactly midday today, everything works except decimal part of the time (milli / micro / nanoseconds).

Image

Produces this code:

Image

Setting 1 millisecond creates the code correctly, but 0 milliseconds fails.

This is the datetime object created:
2025-05-10T12:00:00.809+02:00[Europe/Zurich]

I imagine this is a divide by zero type error.

Trying to do the same thing using the "datetime with date" block:
Image

Produces the datetime object like this (Note the missing minutes):
2025-05-10T12:00+02:00[Europe/Zurich]

But the code looks good (to me):
midday = time.ZonedDateTime.now().withYear(((time.ZonedDateTime.now()).year())).withMonth(((time.ZonedDateTime.now()).monthValue())).withDayOfMonth(((time.ZonedDateTime.now()).dayOfMonth())).withHour(12).withMinute(0).withSecond(0).withNano(0); console.log(midday);

Expected behavior

After running the above, I would expect the z-datetime object to be exactly midday
2025-05-10T12:00:00.000+02:00[Europe/Zurich]

Steps to reproduce

This is a sample rule that can be used to show the issue:

`configuration: {}
triggers: []
conditions: []
actions:

  • inputs: {}
    id: "1"
    configuration:
    blockSource: middaymiddaywith2025-05-0212middaywith2025-05-02midday0middaywith2025-05-02midday0middaywith2025-05-02midday0abcmidday
    type: application/javascript
    script: |
    var midday;

    midday = (time.ZonedDateTime.now()).withHour(12);
    midday = midday.withMinute(0);
    midday = midday.withSecond(0);
    midday = midday;
    console.log(midday);
    

    type: script.ScriptAction
    `

Your environment

  version: 4.3.4
  buildString: Release Build
locale: en-CH
systemInfo:
  configFolder: /openhab/conf
  userdataFolder: /openhab/userdata
  logFolder: /openhab/userdata/logs
  javaVersion: 17.0.14
  javaVendor: Debian
  osName: Linux
  osVersion: 6.12.20+rpt-rpi-2712
  osArchitecture: aarch64
  availableProcessors: 4
  freeMemory: 133488336
  totalMemory: 479199232
  uptime: 724236
  startLevel: 100
addons:
  - automation-jsscripting
  - binding-astro
  - binding-exec
  - binding-harmonyhub
  - binding-mqtt
  - binding-rfxcom
  - binding-systeminfo
  - persistence-jdbc-mariadb
  - persistence-mapdb
  - persistence-rrd4j
  - transformation-jinja
  - transformation-jsonpath
  - transformation-map
  - ui-basic
  - ui-habpanel
clientInfo:
  device:
    ios: false
    android: false
    androidChrome: false
    desktop: true
    iphone: false
    ipod: false
    ipad: false
    edge: false
    ie: false
    firefox: false
    macos: false
    windows: true
    cordova: false
    phonegap: false
    electron: false
    nwjs: false
    webView: false
    webview: false
    standalone: false
    os: windows
    pixelRatio: 1.25
    prefersColorScheme: light
  isSecureContext: false
  locationbarVisible: true
  menubarVisible: true
  navigator:
    cookieEnabled: true
    deviceMemory: N/A
    hardwareConcurrency: 16
    language: en-GB
    languages:
      - en-GB
      - en
      - en-US
      - fr
      - fr-FR
      - fr-CH
    onLine: true
    platform: Win32
  screen:
    width: 1536
    height: 960
    colorDepth: 24
  support:
    touch: false
    pointerEvents: true
    observer: true
    passiveListener: true
    gestures: false
    intersectionObserver: true
  themeOptions:
    dark: dark
    filled: true
    pageTransitionAnimation: default
    bars: light
    homeNavbar: default
    homeBackground: default
    expandableCardAnimation: default
    blocklyRenderer: null
  userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
    like Gecko) Chrome/136.0.0.0 Safari/537.36 Edg/136.0.0.0
timestamp: 2025-05-10T15:45:54.295Z


Browser console

Cannot see any errors in browser console.

Browser network traffic

Cannot see any errors in browser console network.

@Little-Hobo Little-Hobo added bug Something isn't working main ui Main UI labels May 10, 2025
@stefan-hoehn
Copy link
Contributor

@Little-Hobo FYI I am already on that one but it turns out to be much more complicated as it seems to be. The reason is that setting the Nanos includes not only the nanos but also the millis and micros in the underlying API. So I need to implement some clever logic that merges your blocks internally and prevents overwriting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working main ui Main UI
Projects
None yet
Development

No branches or pull requests

2 participants