The method getZonedDateTime() from the type DateTimeType is deprecated

Thanks for reporting this.

Please try this:

if (now.isAfter((Astro_DaylightStart_Time.state as DateTimeType).getZonedDateTime(ZoneId.systemDefault()))) {...

The ZoneId parameter is the time-zone for which you want the ZonedDateTime.

The reason is that DateTimeType no longer contains time-zone, so this will have to be applied. The deprecated method getZonedDateTime() uses ZoneId.systemDefault() internally. However, this can be misleading, since it is no longer the time-zone used when creating the DateTimeType object, because that time-zone is now discarded.

Please see the full explanation here:

I didn’t anticipate that Rules DSL would show these deprecation warnings. Can you confirm that this is only shown when loading the rule, and not when executing it?

I’m now considering a few actions:

  • Add an upgrade note with a deprecation notice that will be shown when upgrading.
  • Ask core maintainers to add a label to the PR so that it will be included in the final release notes.
  • Reconsider if the method should be deprecated:
    • in 4.3
    • in 5.0
    • at all

I think deprecation has both advantages and disadvantages.

3 Likes