@contiva/sap-integration-suite-client
Version:
SAP Cloud Platform Integration API Client
91 lines (90 loc) • 3.71 kB
TypeScript
/**
* Utility functions for SAP date and timestamp formatting
*
* Provides comprehensive date handling utilities for SAP Integration Suite including:
* - Timestamp formatting for API responses
* - OData date filters
* - SAP date format parsing and conversion
*
* @module date-formatter
* @packageDocumentation
*/
/**
* Converts an SAP timestamp to a readable date format
*
* @param {string | number | null | undefined} timestamp - SAP timestamp as string or number (milliseconds since epoch)
* @returns {string} Formatted date as string, or the original value if no valid conversion is possible
*
* @example
* // Basic usage
* const formattedDate = formatSapTimestamp("1617189600000");
* // Returns: "31.03.2021, 12:00:00" (depending on locale)
*
* @example
* // Handle invalid values
* formatSapTimestamp(null); // Returns: ""
* formatSapTimestamp("invalid"); // Returns: "invalid"
*/
export declare function formatSapTimestamp(timestamp: string | number | null | undefined): string;
/**
* Recursively traverse an object and apply timestamp formatting to timestamp fields
*
* This function identifies potential timestamp fields based on field name patterns
* (containing 'date' or 'time') and also specific known SAP timestamp field names.
*
* @param {any} obj - The object to process
* @returns {any} The processed object with formatted timestamps
*
* @example
* // Format timestamps in an API response
* const response = await client.integrationContent.integrationPackages.integrationPackagesList();
* const formattedResponse = formatSapTimestampsInObject(response.data);
*
* // This will format fields like CreationDate, ModifiedDate, etc.
*/
export declare function formatSapTimestampsInObject(obj: any): any;
/**
* Utility functions for SAP date handling in OData requests
* These are primarily used for OData filtering and date conversion
*/
export declare class SapDateUtils {
/**
* Formats a date for SAP OData filter expressions
*
* @param {Date | string} date Date to format
* @returns {string} Formatted date string for SAP OData filtering
*/
static formatDateForFilter(date: Date | string): string;
/**
* Creates an OData datetime filter expression
*
* @param {string} fieldName Name of the date field
* @param {string} operator Comparison operator (eq, ne, gt, ge, lt, le)
* @param {Date | string} date Date value to compare against
* @returns {string} Complete OData filter expression
*/
static createDateTimeFilter(fieldName: string, operator: 'eq' | 'ne' | 'gt' | 'ge' | 'lt' | 'le', date: Date | string): string;
/**
* Parses an SAP OData date string to a JavaScript Date
*
* @param {string} sapDateString Date string in SAP format (e.g. "/Date(1234567890)/")
* @returns {Date | null} JavaScript Date object or null if invalid
*/
static parseSapDate(sapDateString: string): Date | null;
/**
* Formats an SAP OData date string to a readable string
*
* @param {string} sapDateString Date string in SAP format
* @param {Intl.DateTimeFormatOptions} options Formatting options
* @returns {string} Formatted date string or the original if invalid
*/
static formatSapDate(sapDateString: string, options?: Intl.DateTimeFormatOptions): string;
/**
* Ensures that all datetime values in a filter string are properly formatted
* for SAP OData (removing 'Z' and milliseconds)
*
* @param {string} filter The OData filter string to process
* @returns {string} Filter string with correctly formatted datetime values
*/
static sanitizeFilterDatetimes(filter: string): string;
}