diff --git a/api/js/etemplate/Et2Date/Et2DateTimeOnly.ts b/api/js/etemplate/Et2Date/Et2DateTimeOnly.ts new file mode 100644 index 0000000000..2958be7d61 --- /dev/null +++ b/api/js/etemplate/Et2Date/Et2DateTimeOnly.ts @@ -0,0 +1,69 @@ +/** + * EGroupware eTemplate2 - Date+Time widget (WebComponent) + * + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package etemplate + * @subpackage api + * @link https://www.egroupware.org + * @author Nathan Gray + */ + + +import {Et2DateTime} from "./Et2DateTime"; + + +export class Et2DateTimeOnly extends Et2DateTime +{ + static get styles() + { + return [ + ...super.styles, + ]; + } + + static get properties() + { + return { + ...super.properties + } + } + + constructor() + { + super(); + + // Configure flatpickr + let timeFormat = ((window.egw.preference("timeformat") || "24") == "24" ? "H:i" : "h:i K"); + this.altFormat = timeFormat; + this.enableTime = true; + this.noCalendar = true; + this.time_24hr = this.egw().preference("timeformat", "common") == "24"; + this.dateFormat = "1970-01-01TH:i:00\\Z"; + this.defaultHour = new Date().getHours(); + } + + set_value(value) + { + if(!value || value == 0 || value == "0") + { + value = ''; + } + // Handle timezone offset, flatpickr uses local time + let date = new Date(value); + let formatDate = new Date(date.valueOf() + date.getTimezoneOffset() * 60 * 1000); + formatDate.setDate(1); + formatDate.setMonth(0) + formatDate.setFullYear(1970); + if(!this._instance) + { + this.defaultDate = formatDate; + } + else + { + this.setDate(formatDate); + } + } +} + +// @ts-ignore TypeScript is not recognizing that this is a LitElement +customElements.define("et2-date-timeonly", Et2DateTimeOnly); diff --git a/api/js/etemplate/etemplate2.ts b/api/js/etemplate/etemplate2.ts index c6eb309336..e8ef2d5b6b 100644 --- a/api/js/etemplate/etemplate2.ts +++ b/api/js/etemplate/etemplate2.ts @@ -31,6 +31,7 @@ import './Et2Date/Et2DateDurationReadonly'; import './Et2Date/Et2DateReadonly'; import './Et2Date/Et2DateSinceReadonly'; import './Et2Date/Et2DateTime'; +import './Et2Date/Et2DateTimeOnly'; import './Et2Date/Et2DateTimeReadonly'; import './Et2Date/Et2DateTimeToday'; import './Et2Description/Et2Description';