TBEL Helper Functions
TBEL provides a rich set of built-in helper functions for encoding, byte manipulation, hex conversion, date/time, and geofencing. For language syntax and data types, see the Language Guide.
Encoding
Section titled “Encoding”Creates a Base64-encoded ASCII string from a binary string.
| Parameter | Type | Description |
|---|---|---|
input | String | The binary string to encode |
Returns: String — Base64-encoded string.
var encodedData = btoa("Hello, world"); // encode a stringvar decodedData = atob(encodedData); // decode the stringDecodes a Base64-encoded string back to a binary string.
| Parameter | Type | Description |
|---|---|---|
input | String | Base64-encoded string |
Returns: String — decoded binary string.
var encodedData = btoa("Hello, world");var decodedData = atob(encodedData); // "Hello, world"Number rounding
Section titled “Number rounding”toFixed
Section titled “toFixed”Rounds a double value towards the nearest neighbor with the given precision.
| Parameter | Type | Description |
|---|---|---|
value | double | The value to round |
precision | int | Number of decimal places |
Returns: double — rounded value.
toFixed(0.345, 1); // 0.3toFixed(0.345, 2); // 0.35Rounds a double value to the nearest integer.
| Parameter | Type | Description |
|---|---|---|
value | double | The value to round |
Returns: int — rounded integer.
toInt(0.3); // 0toInt(0.5); // 1toInt(2.7); // 3String and byte conversion
Section titled “String and byte conversion”stringToBytes
Section titled “stringToBytes”Converts a string to a list of bytes.
| Parameter | Type | Description |
|---|---|---|
input | String | The string to convert |
charsetName | String | Optional charset (default: UTF-8) |
Returns: List — list of byte values.
stringToBytes("hello world");// [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]
var base64Str = "eyJoZWxsbyI6ICJ3b3JsZCJ9";var bytesStr = atob(base64Str);stringToBytes(bytesStr);// [123, 34, 104, 101, 108, 108, 111, 34, 58, 32, 34, 119, 111, 114, 108, 100, 34, 125]
stringToBytes("hello world", "UTF8");// [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]bytesToString
Section titled “bytesToString”Creates a string from a list of bytes.
| Parameter | Type | Description |
|---|---|---|
bytesList | List | A list of byte values |
charsetName | String | Optional charset (default: UTF-8) |
Returns: String — decoded string.
var bytes = [0x48, 0x45, 0x4C, 0x4C, 0x4F];bytesToString(bytes); // "HELLO"decodeToString
Section titled “decodeToString”Alias for bytesToString.
decodeToJson
Section titled “decodeToJson”Decodes a list of bytes to a JSON document.
| Parameter | Type | Description |
|---|---|---|
bytesList | List | A list of byte values |
Returns: JSON object or primitive.
var base64Str = "eyJoZWxsbyI6ICJ3b3JsZCJ9";var bytesStr = atob(base64Str);var bytes = stringToBytes(bytesStr);decodeToJson(bytes); // {"hello": "world"}Type validation
Section titled “Type validation”isBinary
Section titled “isBinary”Checks whether a string represents a binary (base-2) value.
| Parameter | Type | Description |
|---|---|---|
str | String | The string to check |
Returns: int — 2 if binary, -1 otherwise.
isBinary("1100110"); // 2isBinary("2100110"); // -1isOctal
Section titled “isOctal”Checks whether a string represents an octal (base-8) value.
| Parameter | Type | Description |
|---|---|---|
str | String | The string to check |
Returns: int — 8 if octal, -1 otherwise.
isOctal("4567734"); // 8isOctal("8100110"); // -1isDecimal
Section titled “isDecimal”Checks whether a string represents a decimal (base-10) value.
| Parameter | Type | Description |
|---|---|---|
str | String | The string to check |
Returns: int — 10 if decimal, -1 otherwise.
isDecimal("4567039"); // 10isDecimal("C100110"); // -1isHexadecimal
Section titled “isHexadecimal”Checks whether a string represents a hexadecimal (base-16) value.
| Parameter | Type | Description |
|---|---|---|
str | String | The string to check |
Returns: int — 16 if hexadecimal, -1 otherwise.
isHexadecimal("F5D7039"); // 16isHexadecimal("K100110"); // -1Checks whether a double value is Not-a-Number.
| Parameter | Type | Description |
|---|---|---|
value | double | The value to check |
Returns: boolean — true if NaN.
isNaN(0.0 / 0.0); // trueisNaN(1.0); // falseURI encoding
Section titled “URI encoding”encodeURI
Section titled “encodeURI”Encodes a URI string, preserving reserved characters: A–Z a–z 0–9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , #
| Parameter | Type | Description |
|---|---|---|
uri | String | The URI to encode |
Returns: String — encoded URI.
var uri = "-_.!~*'();/?:@&=+$,#ht://example.ж д a/path with spaces/?param1=Київ 1¶m2=Україна2";encodeURI(uri);// "-_.!~*'();/?:@&=+$,#ht://example.%D0%B6%20%D0%B4%20a/path%20with%20spaces/?param1=%D0%9A%D0%B8%D1%97%D0%B2%201¶m2=%D0%A3%D0%BA%D1%80%D0%B0%D1%97%D0%BD%D0%B02"decodeURI
Section titled “decodeURI”Decodes a URI previously encoded with encodeURI.
| Parameter | Type | Description |
|---|---|---|
uri | String | The encoded URI |
Returns: String — decoded URI.
var encoded = "-_.!~*'();/?:@&=+$,#ht://example.%D0%B6%20%D0%B4%20a/path%20with%20spaces/?param1=%D0%9A%D0%B8%D1%97%D0%B2%201¶m2=%D0%A3%D0%BA%D1%80%D0%B0%D1%97%D0%BD%D0%B02";decodeURI(encoded);// "-_.!~*'();/?:@&=+$,#ht://example.ж д a/path with spaces/?param1=Київ 1¶m2=Україна2"Utility
Section titled “Utility”raiseError
Section titled “raiseError”Throws a RuntimeException with the given message.
| Parameter | Type | Description |
|---|---|---|
message | String | Exception message |
raiseError("frequency_weighting_type must be 0, 1 or 2.");// throws RuntimeException: "frequency_weighting_type must be 0, 1 or 2."
var value = 4;var message = "frequency_weighting_type must be 0, 1 or 2. A value of " + value + " is invalid.";raiseError(message);// throws RuntimeException with the composed messageprintUnsignedBytes
Section titled “printUnsignedBytes”Converts a list of signed bytes to their unsigned integer representation.
| Parameter | Type | Description |
|---|---|---|
byteArray | List | List of signed byte values |
Returns: List — unsigned byte values (0–255).
var list = hexToBytes("D8FF");printUnsignedBytes(list); // [216, 255]
var list2 = hexToBytes("FFD8");printUnsignedBytes(list2); // [255, 216]String padding
Section titled “String padding”padStart
Section titled “padStart”Pads a string from the start until the target length is reached.
| Parameter | Type | Description |
|---|---|---|
str | String | The string to pad |
targetLength | int | Desired result length |
padString | char | Character to pad with |
Returns: String — padded string. If the string is already at or beyond the target length, it is returned unchanged.
padStart("010011", 8, '0'); // "00010011"padStart("1001010011", 8, '0'); // "1001010011" (already >= 8)padStart("1001010011", 16, '*'); // "******1001010011"
var fullNumber = "203439900FFCD5581";var last6 = fullNumber.substring(11);padStart(last6, fullNumber.length(), '*'); // "***********CD5581"padEnd
Section titled “padEnd”Pads a string from the end until the target length is reached.
| Parameter | Type | Description |
|---|---|---|
str | String | The string to pad |
targetLength | int | Desired result length |
padString | char | Character to pad with |
Returns: String — padded string. If the string is already at or beyond the target length, it is returned unchanged.
padEnd("010011", 8, '0'); // "01001100"padEnd("1001010011", 8, '0'); // "1001010011" (already >= 8)padEnd("1001010011", 16, '*'); // "1001010011******"
var fullNumber = "203439900FFCD5581";var first11 = fullNumber.substring(0, 11);padEnd(first11, fullNumber.length(), '*'); // "203439900FF******"Number-to-hex conversion
Section titled “Number-to-hex conversion”intToHex
Section titled “intToHex”Converts an integer to a hexadecimal string.
| Parameter | Type | Description |
|---|---|---|
i | Integer | The integer to convert |
bigEndian | boolean | Optional. Big-endian byte order (default: true) |
pref | boolean | Optional. Include 0x prefix (default: false) |
len | int | Optional. Number of bytes to include |
Returns: String — hex string.
intToHex(0x7FFFFFFF, true, true); // "0x7FFFFFFF"intToHex(171, true, false); // "AB"intToHex(0xABCDEF, false, true, 4); // "0xCDAB"intToHex(0xABCD, false, false, 2); // "AB"longToHex
Section titled “longToHex”Converts a long to a hexadecimal string.
| Parameter | Type | Description |
|---|---|---|
l | Long | The long to convert |
bigEndian | boolean | Optional. Big-endian byte order (default: true) |
pref | boolean | Optional. Include 0x prefix (default: false) |
len | int | Optional. Number of bytes to include |
Returns: String — hex string.
longToHex(9223372036854775807, true, true); // "0x7FFFFFFFFFFFFFFF"longToHex(0x7A12BCD3, true, true, 4); // "0xBCD3"longToHex(0x7A12BCD3, false, false, 4); // "127A"floatToHex
Section titled “floatToHex”Converts a float to a hexadecimal string using IEEE 754 representation.
| Parameter | Type | Description |
|---|---|---|
f | Float | The float to convert |
bigEndian | boolean | Optional. Big-endian byte order (default: true) |
Returns: String — hex string with 0x prefix.
floatToHex(123456789.00); // "0x4CEB79A3"floatToHex(123456789.00, false); // "0xA379EB4C"doubleToHex
Section titled “doubleToHex”Converts a double to a hexadecimal string using IEEE 754 representation.
| Parameter | Type | Description |
|---|---|---|
d | Double | The double to convert |
bigEndian | boolean | Optional. Big-endian byte order (default: true) |
Returns: String — hex string with 0x prefix.
doubleToHex(1729.1729d); // "0x409B04B10CB295EA"doubleToHex(1729.1729d, false); // "0xEA95B20CB1049B40"intLongToRadixString
Section titled “intLongToRadixString”Converts a number to a string in the specified radix (binary, octal, decimal, or hex).
| Parameter | Type | Description |
|---|---|---|
number | Long | The number to convert |
radix | int | Optional. Base: 2, 8, 10, or 16 (default: 10) |
bigEndian | boolean | Optional. Big-endian byte order (default: true) |
pref | boolean | Optional. Include 0x prefix for hex (default: false) |
Returns: String — the number in the specified radix.
intLongToRadixString(58, 2); // "00111010"intLongToRadixString(9223372036854775807, 2); // "0111111111...1" (63 digits)intLongToRadixString(13158, 8); // "31546"intLongToRadixString(-13158, 8); // "1777777777777777746232"intLongToRadixString(-13158, 10); // "-13158"intLongToRadixString(13158, 16); // "3366"intLongToRadixString(-13158, 16); // "FFCC9A"intLongToRadixString(9223372036854775807, 16); // "7FFFFFFFFFFFFFFF"intLongToRadixString(-13158, 16, true, true); // "0xFFCC9A"Hex string parsing
Section titled “Hex string parsing”parseHexToInt
Section titled “parseHexToInt”Parses a hexadecimal string to an integer.
| Parameter | Type | Description |
|---|---|---|
hex | String | Hexadecimal string |
bigEndian | boolean | Optional. Big-endian byte order (default: true) |
Returns: int — parsed integer.
parseHexToInt("BBAA"); // 48042parseHexToInt("BBAA", true); // 48042parseHexToInt("AABB", false); // 48042parseHexToInt("BBAA", false); // 43707Aliases:
parseLittleEndianHexToInt(hex)— equivalent toparseHexToInt(hex, false)parseBigEndianHexToInt(hex)— equivalent toparseHexToInt(hex, true)
parseHexToFloat
Section titled “parseHexToFloat”Parses a hexadecimal string to a float (IEEE 754).
| Parameter | Type | Description |
|---|---|---|
hex | String | Hexadecimal string |
bigEndian | boolean | Optional. Big-endian byte order (default: true) |
Returns: float — parsed float.
parseHexToFloat("41EA62CC"); // 29.29824parseHexToFloat("41EA62CC", true); // 29.29824parseHexToFloat("41EA62CC", false); // -5.948442E7parseHexToFloat("CC62EA41", false); // 29.29824Aliases:
parseLittleEndianHexToFloat(hex)— equivalent toparseHexToFloat(hex, false)parseBigEndianHexToFloat(hex)— equivalent toparseHexToFloat(hex, true)
parseHexIntLongToFloat
Section titled “parseHexIntLongToFloat”Interprets a hex string as a plain integer value and returns it as a float.
Unlike parseHexToFloat, this does not use IEEE 754 bit interpretation.
| Parameter | Type | Description |
|---|---|---|
hex | String | Hexadecimal string (may include 0x prefix) |
bigEndian | boolean | Big-endian byte order |
Returns: float — the integer value as a float.
parseHexIntLongToFloat("0x0A", true); // 10.0parseHexIntLongToFloat("0x0A", false); // 10.0parseHexIntLongToFloat("0x00000A", true); // 10.0parseHexIntLongToFloat("0x0A0000", false); // 10.0parseHexIntLongToFloat("0x000A0A", true); // 2570.0parseHexIntLongToFloat("0x0A0A00", false); // 2570.0parseHexToDouble
Section titled “parseHexToDouble”Parses a hexadecimal string to a double (IEEE 754).
| Parameter | Type | Description |
|---|---|---|
hex | String | Hexadecimal string |
bigEndian | boolean | Optional. Big-endian byte order (default: true) |
Returns: double — parsed double.
parseHexToDouble("409B04B10CB295EA"); // 1729.1729parseHexToDouble("409B04B10CB295EA", true); // 1729.1729parseHexToDouble("409B04B10CB295EA", false); // -2.7208640774822924E205parseHexToDouble("EA95B20CB1049B40", false); // 1729.1729Aliases:
parseLittleEndianHexToDouble(hex)— equivalent toparseHexToDouble(hex, false)parseBigEndianHexToDouble(hex)— equivalent toparseHexToDouble(hex, true)
Hex and byte conversion
Section titled “Hex and byte conversion”hexToBytes
Section titled “hexToBytes”Converts a hexadecimal string to a list of byte values.
| Parameter | Type | Description |
|---|---|---|
hex | String | Hexadecimal string |
Returns: List — list of signed byte values (-128 to 127).
hexToBytes("D8FF"); // [-40, -1]hexToBytesArray
Section titled “hexToBytesArray”Converts a hexadecimal string to a byte array.
| Parameter | Type | Description |
|---|---|---|
hex | String | Hexadecimal string |
Returns: int[] — byte array.
bytesToHex
Section titled “bytesToHex”Converts a list of bytes to a hexadecimal string.
| Parameter | Type | Description |
|---|---|---|
bytesList | List | List of byte values |
Returns: String — hexadecimal string.
Byte parsing
Section titled “Byte parsing”parseBytesToInt
Section titled “parseBytesToInt”Parses a list of bytes to an integer.
| Parameter | Type | Description |
|---|---|---|
bytesList | List | List of byte values |
bigEndian | boolean | Optional. Big-endian byte order (default: true) |
Returns: int — parsed integer.
parseBytesToInt([0xBB, 0xAA]); // 48042parseBytesToInt([0xBB, 0xAA], true); // 48042parseBytesToInt([0xAA, 0xBB], false); // 48042parseBytesToLong
Section titled “parseBytesToLong”Parses a list of bytes to a long.
| Parameter | Type | Description |
|---|---|---|
bytesList | List | List of byte values |
bigEndian | boolean | Optional. Big-endian byte order (default: true) |
Returns: long — parsed long.
parseBytesToFloat
Section titled “parseBytesToFloat”Parses a list of bytes to a float (IEEE 754).
| Parameter | Type | Description |
|---|---|---|
bytesList | List | List of byte values |
bigEndian | boolean | Optional. Big-endian byte order (default: true) |
Returns: float — parsed float.
parseBytesIntToFloat
Section titled “parseBytesIntToFloat”Interprets a list of bytes as an integer and returns it as a float.
| Parameter | Type | Description |
|---|---|---|
bytesList | List | List of byte values |
bigEndian | boolean | Optional. Big-endian byte order (default: true) |
Returns: float — the integer value as a float.
parseBytesLongToDouble
Section titled “parseBytesLongToDouble”Interprets a list of bytes as a long and returns it as a double.
| Parameter | Type | Description |
|---|---|---|
bytesList | List | List of byte values |
bigEndian | boolean | Optional. Big-endian byte order (default: true) |
Returns: double — the long value as a double.
bytesToExecutionArrayList
Section titled “bytesToExecutionArrayList”Converts a list of bytes to an ExecutionArrayList (TBEL’s internal list type).
| Parameter | Type | Description |
|---|---|---|
bytesList | List | List of byte values |
Returns: List — execution array list.
Binary arrays
Section titled “Binary arrays”parseByteToBinaryArray
Section titled “parseByteToBinaryArray”Converts a single byte to an 8-element binary array.
| Parameter | Type | Description |
|---|---|---|
b | int | A single byte value |
Returns: int[] — array of 8 binary digits (0 or 1).
parseByteToBinaryArray(0xFF); // [1, 1, 1, 1, 1, 1, 1, 1]parseByteToBinaryArray(0x00); // [0, 0, 0, 0, 0, 0, 0, 0]parseBytesToBinaryArray
Section titled “parseBytesToBinaryArray”Converts a list of bytes to a binary array.
| Parameter | Type | Description |
|---|---|---|
bytesList | List | List of byte values |
Returns: int[] — binary array (8 bits per byte).
parseBytesToBinaryArray([0xFF, 0x00]);// [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]parseLongToBinaryArray
Section titled “parseLongToBinaryArray”Converts a long to a 64-element binary array.
| Parameter | Type | Description |
|---|---|---|
value | long | The long value |
Returns: int[] — array of 64 binary digits.
parseLongToBinaryArray(255L);// [0,0,...,0, 1,1,1,1,1,1,1,1] (56 zeros followed by 8 ones)parseBinaryArrayToInt
Section titled “parseBinaryArrayToInt”Converts a binary array to an integer.
| Parameter | Type | Description |
|---|---|---|
binaryArray | int[] | Array of binary digits (0s and 1s) |
Returns: int — parsed integer.
parseBinaryArrayToInt([1, 1, 1, 1, 1, 1, 1, 1]); // 255parseBinaryArrayToInt([0, 0, 1, 1, 1, 0, 1, 0]); // 58Number parsing
Section titled “Number parsing”parseInt
Section titled “parseInt”Parses a string to an integer.
| Parameter | Type | Description |
|---|---|---|
str | String | The string to parse |
Returns: int — parsed integer.
parseInt("123"); // 123parseLong
Section titled “parseLong”Parses a string to a long.
| Parameter | Type | Description |
|---|---|---|
str | String | The string to parse |
Returns: long — parsed long.
parseLong("9223372036854775807"); // 9223372036854775807parseFloat
Section titled “parseFloat”Parses a string to a float.
| Parameter | Type | Description |
|---|---|---|
str | String | The string to parse |
Returns: float — parsed float.
parseFloat("3.14"); // 3.14parseDouble
Section titled “parseDouble”Parses a string to a double.
| Parameter | Type | Description |
|---|---|---|
str | String | The string to parse |
Returns: double — parsed double.
parseDouble("3.141592653589793"); // 3.141592653589793Bitwise operations
Section titled “Bitwise operations”TBEL supports standard bitwise operators inherited from Java:
| Operator | Description | Example |
|---|---|---|
& | AND | 0xFF & 0x0F → 0x0F |
| | OR | 0xF0 | 0x0F → 0xFF |
^ | XOR | 0xFF ^ 0x0F → 0xF0 |
~ | NOT (complement) | ~0x00 → -1 |
<< | Left shift | 1 << 8 → 256 |
>> | Signed right shift | -256 >> 4 → -16 |
>>> | Unsigned right shift | -1 >>> 28 → 15 |
var a = 0xFF;var b = 0x0F;var andResult = a & b; // 15 (0x0F)var orResult = a | b; // 255 (0xFF)var xorResult = a ^ b; // 240 (0xF0)var shifted = 1 << 8; // 256Base64 conversion
Section titled “Base64 conversion”base64ToHex
Section titled “base64ToHex”Converts a Base64-encoded string to a hexadecimal string.
| Parameter | Type | Description |
|---|---|---|
base64Str | String | Base64-encoded string |
Returns: String — hexadecimal string.
base64ToHex("SGVsbG8gV29ybGQ="); // "48656C6C6F20576F726C64"bytesToBase64
Section titled “bytesToBase64”Converts a list of bytes to a Base64 string.
| Parameter | Type | Description |
|---|---|---|
bytesList | List | List of byte values |
Returns: String — Base64-encoded string.
bytesToBase64([72, 101, 108, 108, 111]); // "SGVsbG8="base64ToBytes
Section titled “base64ToBytes”Converts a Base64 string to a list of bytes.
| Parameter | Type | Description |
|---|---|---|
base64Str | String | Base64-encoded string |
Returns: List — list of byte values.
base64ToBytes("SGVsbG8gV29ybGQ=");// [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]base64ToBytesList
Section titled “base64ToBytesList”Alias for base64ToBytes.
JSON flattening
Section titled “JSON flattening”toFlatMap
Section titled “toFlatMap”Flattens a nested JSON structure into a single-level map where nested keys are joined with dots.
Overload 1 — basic flattening:
var json = {"temperature": 42, "nested": {"humidity": 73}};toFlatMap(json);// {"temperature": 42, "nested.humidity": 73}Overload 2 — with pathInKey flag:
| Parameter | Type | Description |
|---|---|---|
json | Object | JSON object or string |
pathInKey | boolean | true to include full path in keys, false to use only the leaf key |
var json = {"temperature": 42, "nested": {"humidity": 73}};toFlatMap(json, true); // {"temperature": 42, "nested.humidity": 73}toFlatMap(json, false); // {"temperature": 42, "humidity": 73}Overload 3 — with exclusion list:
| Parameter | Type | Description |
|---|---|---|
json | Object | JSON object or string |
excludeList | List | Paths to exclude from flattening |
var json = {"temperature": 42, "nested": {"humidity": 73, "pressure": 1013}};toFlatMap(json, ["pressure"]);// {"temperature": 42, "nested.humidity": 73}Overload 4 — with exclusion list and pathInKey:
| Parameter | Type | Description |
|---|---|---|
json | Object | JSON object or string |
excludeList | List | Paths to exclude from flattening |
pathInKey | boolean | true to include full path in keys |
var json = {"temperature": 42, "nested": {"humidity": 73, "pressure": 1013}};toFlatMap(json, ["pressure"], true);// {"temperature": 42, "nested.humidity": 73}Date and time (tbDate)
Section titled “Date and time (tbDate)”The Date class provides date/time creation and arithmetic.
Creating a date from a string
Section titled “Creating a date from a string”var date1 = new Date("2024-01-15");var date2 = new Date("15/01/2024", "dd/MM/yyyy");var date3 = new Date("15/01/2024", "dd/MM/yyyy", "en_US");var date4 = new Date("15/01/2024", "dd/MM/yyyy", "en_US", "UTC");| Parameter | Type | Description |
|---|---|---|
dateString | String | The date string to parse |
pattern | String | Optional. Date format pattern (e.g. dd/MM/yyyy) |
locale | String | Optional. Locale (e.g. en_US, fr_FR) |
timeZone | String | Optional. Time zone (e.g. UTC, America/New_York) |
Creating a date from components
Section titled “Creating a date from components”var date1 = new Date(2024, 1, 15);var date2 = new Date(2024, 1, 15, 14, 30, 45);var date3 = new Date(2024, 1, 15, "UTC");var date4 = new Date(2024, 1, 15, 14, 30, 45, "UTC");Creating a date with options map
Section titled “Creating a date with options map”var options = { pattern: "yyyy-MM-dd HH:mm:ss", locale: "en_US", timeZone: "UTC"};var date = new Date("2024-01-15 14:30:45", options);Date arithmetic
Section titled “Date arithmetic”Each method modifies the date in-place and returns the modified date:
var date = new Date(2024, 1, 15);date.addYears(1); // 2025-01-15date.addMonths(2); // 2025-03-15date.addWeeks(1); // 2025-03-22date.addDays(5); // 2025-03-27date.addHours(3); // 2025-03-27 03:00date.addMinutes(30); // 2025-03-27 03:30date.addSeconds(45); // 2025-03-27 03:30:45date.addMilliseconds(500); // 2025-03-27 03:30:45.500Geofencing
Section titled “Geofencing”isInsidePolygon
Section titled “isInsidePolygon”Checks whether a geographic point lies inside a polygon boundary.
| Parameter | Type | Description |
|---|---|---|
latitude | double | Point latitude |
longitude | double | Point longitude |
polygon | List | List of [latitude, longitude] pairs defining the polygon vertices |
Returns: boolean — true if the point is inside the polygon.
var polygon = [ [55.75, 37.61], [55.75, 37.62], [55.74, 37.62], [55.74, 37.61]];isInsidePolygon(55.745, 37.615, polygon); // trueisInsideCircle
Section titled “isInsideCircle”Checks whether a geographic point lies inside a circle.
| Parameter | Type | Description |
|---|---|---|
latitude | double | Point latitude |
longitude | double | Point longitude |
centerLatitude | double | Circle center latitude |
centerLongitude | double | Circle center longitude |
radiusInKm | double | Circle radius in kilometers |
Returns: boolean — true if the point is inside the circle.
isInsideCircle(55.745, 37.615, 55.75, 37.62, 1.5); // true (within 1.5 km)