scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
57 lines • 1.28 kB
JavaScript
import { AbsDateFormatter } from "scriptable-abstract";
class MockDateFormatter extends AbsDateFormatter {
constructor() {
super({
locale: "en-US",
dateFormat: ""
});
}
/**
* Gets the locale identifier
*/
get locale() {
return this.state.locale.replace("-", "_");
}
/**
* Sets the locale identifier
*/
set locale(value) {
const [lang, region] = value.toLowerCase().split("_");
this.setState({ locale: `${lang}-${region?.toUpperCase() || ""}`.replace(/-$/, "") });
}
/**
* Gets the custom date format string
*/
get dateFormat() {
return this.state.dateFormat;
}
/**
* Sets the custom date format string
*/
set dateFormat(value) {
this.setState({ dateFormat: value });
}
/**
* Formats a date into a string
* @param date Date to format
* @returns Formatted date string
*/
string(date) {
if (this.dateFormat) {
return date.toLocaleString(this.state.locale);
}
return date.toLocaleString(this.state.locale);
}
/**
* Parses a string into a date
* @param dateString String to parse
* @returns Parsed date
*/
date(dateString) {
return new Date(dateString);
}
}
export {
MockDateFormatter
};
//# sourceMappingURL=date-formatter.js.map