@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
100 lines (99 loc) • 4.93 kB
TypeScript
import ITimeOptions, { TimeMode, TimeResolution } from './itimeoptions.js';
import Filter from 'ol/format/filter/Filter.js';
export declare const TIME_RANGE_SEPARATOR = "/";
/**
* A class for formatting date and time values based on an `ITimeOption` object.
* Provides utility functions for parsing dates and date ranges, validating them,
* and generating formatted query strings for temporal layer filtering.
*
* The class allows customized configurations through its constructor options, including setting
* minimum and maximum date bounds, default values, resolution levels, and operation modes.
*/
declare class LayerTimeFormatter {
minValue: Date;
maxValue: Date;
resolution: TimeResolution;
mode: TimeMode;
minDefaultValue?: Date;
maxDefaultValue?: Date;
constructor(options?: ITimeOptions);
/**
* Receives a date string or date object, validates it against the specified time options,
* and generates a formatted query string for usage as URL query parameter.
*
* @param {string|Date} date - The date-like string or date object to be parsed and converted.
* @return {string} A formatted query string, or an empty string if the date is invalid.
*/
formatDateString(date: string | Date): string;
/**
* Generates a formatted query string from a provided date range for usage as URL query parameter.
* The provided dates are shortened to fit the defined resolution.
*
* @param lowerLimit The lower bound of the time range as a date-like string or date object.
* @param upperLimit The upper bound of the time range as a date-like string or date object.
* @return A formatted query string, or an empty string if the dates are invalid.
*/
formatTimeRange(lowerLimit: string | Date, upperLimit: string | Date): string;
/**
* Simple date transform method from a date-like string to a date object without validating it against the time options.
*
* @param {string} dateStr - The date string to be parsed.
* @return {Date | undefined} The resulting Date object if the input is valid, otherwise undefined.
*/
parseDateString(dateStr: string): Date | undefined;
/**
* Helper method to quickly generate a formated query string from the default time restriction
* provided by the time options.
*
* @return {string | undefined} The formatted defaults as query string or undefined if no defaults are available.
*/
getFormattedDefault(): string | undefined;
/**
* Converts the WMS temporal query string into an OpenLayers WFS filter.
*
* @param {string} timeRestriction - The time restriction query string used for the WMS request, e.g. '2020-02', '2012-11-04/2012-11-14'.
* @param {string} timeAttribute - The name of the attribute that is used for temporal filtering.
* @return {Filter | undefined} Returns a new OpenLayers WFS filter object, or undefined if no valid filter could be created.
*/
toOpenLayersWfsFilter(timeRestriction: string, timeAttribute: string): Filter | undefined;
private isValidDateString;
private isWithinRange;
/**
* Formats a given date into a date string of type 'YYYY-MM-DD'.
*/
private static formatAsDate;
private static getMondayOfWeek;
private static getSundayOfWeek;
/**
* Formats a given date into a string, representing the week range from Monday to Sunday that the date falls into,
* e.g. 'YYYY-MM-DD/YYYY-MM-DD'
*/
private static formatAsWeekRange;
/**
* Formats a given date into a date string of type 'YYYY-MM'.
*/
private static formatAsMonth;
/**
* Formats a given date into a year string of type 'YYYY'.
*/
private static formatAsYear;
/**
* Constructs a query string based on a single date value and a specified time resolution.
*
* @param {Date} date - The date value to be formatted.
* @param {TimeResolution} resolution - The time resolution specifying the format (e.g. day, week, month, year).
* @return {string} A formatted string representation of the date based on the provided resolution.
*/
static queryStringFromSingleValueAndResolution(date: Date, resolution: TimeResolution): string;
/**
* Formats a date range as a string, separated by a forward slash and taking the resolution into account
* when defining the precision of the date strings.
*
* @param {Date} lowerLimit - The starting date of the range.
* @param {Date} upperLimit - The ending date of the range.
* @param {TimeResolution} resolution - The resolution of the date range, can be 'day', 'week', 'month', or 'year'.
* @return {string} A query string representing the date range formatted according to the specified resolution.
*/
private static queryStringFromDateRangeAnResolution;
}
export default LayerTimeFormatter;