egroupware/api/js/etemplate/Et2Date/Et2DateTimeOnly.ts

74 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-02-16 18:43:15 +01:00
/**
* 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 = ((<string>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)
{
let adjustedValue : Date | string = '';
2022-02-16 18:43:15 +01:00
if(!value || value == 0 || value == "0")
{
value = '';
}
// Handle timezone offset, flatpickr uses local time
if(value)
{
let date = new Date(value);
adjustedValue = new Date(date.valueOf() + date.getTimezoneOffset() * 60 * 1000);
adjustedValue.setDate(1);
adjustedValue.setMonth(0)
adjustedValue.setFullYear(1970);
}
2022-02-16 18:43:15 +01:00
if(!this._instance)
{
this.defaultDate = adjustedValue;
2022-02-16 18:43:15 +01:00
}
else
{
this.setDate(adjustedValue);
2022-02-16 18:43:15 +01:00
}
}
}
// @ts-ignore TypeScript is not recognizing that this is a LitElement
customElements.define("et2-date-timeonly", Et2DateTimeOnly);