import FieldsIndex from "@arcgis/core/layers/support/FieldsIndex.js";const FieldsIndex = await $arcgis.import("@arcgis/core/layers/support/FieldsIndex.js");- Since
- ArcGIS Maps SDK for JavaScript 4.12
This class provides convenient methods that can be used to make case-insensitive lookups for a field by its name. It also provides more information such as the list of date fields in a layer.
Constructors
Properties
| Property | Type | Class |
|---|---|---|
dateFields readonly | T[] | |
Methods
| Method | Signature | Class |
|---|---|---|
get(fieldName: string | null | undefined): T | null | undefined | | |
getTimeZone(fieldOrFieldName: T | string | null | undefined): string | null | undefined | | |
has(fieldName: string): boolean | | |
isDateField(fieldName: string | null | undefined): boolean | |
getTimeZone
Method
- Signature
-
getTimeZone (fieldOrFieldName: T | string | null | undefined): string | null | undefined
Returns a time zone for a field.
Use this method to ensure queries in the following places are issued in the time zone of the given date field:
The following table explains the value returned from this method:
| Field type | Returned value |
|---|---|
| Date field | Returns the time zone associated with the date field. Returns unknown if the layer's date fields are in unknown time zone. |
| Date-only, Time-only or Timestamp-offset field | Returns unknown as services do not have time zone associated with date-only, time-only and timestamp-offset fields. Date-only and time-only fields are time zone agnostic. Timestamp-offset field values store its time offset. |
| All other fields | Returns null. |
Parameters
Example
// Query for features that recorded on January 1, 2012 9:00:00 AM GMT// DateTime_PST date field values are in PST. Must adjust the epoch values to PST
const queryDate = new Date(1325408400000); 01/01/2012 9:00:00 AM GMTlet queryFields = ["DateTime_PST"];
// get the timezone of the DateTime_PST date fieldconst fieldTimeZone = layer.fieldsIndex.getTimeZone("DateTime_PST") ;
// we need to adjust the date value to match the time zone of the field.const where = `DateTime_PST < DATE '${getDateForTimeZone(queryDate, fieldTimeZone)}'`layerView.filter = new FeatureFilter({ where});runQueries(where, queryFields);
// This function conveniently formats a date in terms of the parsed time zone.function getDateForTimeZone(queryDate, timezone) {
// adjust the given date field to the timezone of the date field const zonedDate = new Date( queryDate.toLocaleString("en-US", { timeZone: timezone }) ); const pad = (value) => String(value).padStart(2, "0"); const month = pad(zonedDate.getMonth() + 1); const day = pad(zonedDate.getDate()) const year = zonedDate.getFullYear(); const hour = pad(zonedDate.getHours()); const minutes = pad(zonedDate.getMinutes()); const seconds = pad(zonedDate.getSeconds());
return `${year}-${month}-${day} ${hour}:${minutes}:${seconds}`;}