Added basic time-related classes for usage in script and ruled (#2587)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
pull/2605/head
Christoph Weitkamp 2021-12-10 23:41:08 +01:00 committed by GitHub
parent f641d1d6ec
commit 793ced6286
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -17,6 +17,10 @@ import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
@ -147,12 +151,18 @@ public class DefaultScriptScopeProvider implements ScriptExtensionProvider {
elements.put("PointType", PointType.class);
elements.put("StringType", StringType.class);
elements.put("SIUnits", SIUnits.class);
elements.put("ImperialUnits", ImperialUnits.class);
elements.put("MetricPrefix", MetricPrefix.class);
elements.put("SIUnits", SIUnits.class);
elements.put("Units", Units.class);
elements.put("BinaryPrefix", BinaryPrefix.class);
// date time static functions
elements.put("ChronoUnit", ChronoUnit.class);
elements.put("Duration", Duration.class);
elements.put("ZoneId", ZoneId.class);
elements.put("ZonedDateTime", ZonedDateTime.class);
// services
elements.put("items", new ItemRegistryDelegate(itemRegistry));
elements.put("ir", itemRegistry);

View File

@ -15,7 +15,10 @@ package org.openhab.core.model.script.scoping;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.time.Duration;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
@ -100,6 +103,9 @@ public class ScriptImplicitlyImportedTypes extends ImplicitlyImportedFeatures {
result.add(BinaryPrefix.class);
// date time static functions
result.add(ChronoUnit.class);
result.add(Duration.class);
result.add(ZoneId.class);
result.add(ZonedDateTime.class);
result.addAll(getActionClasses());