2022-02-03 22:58:56 +01:00
|
|
|
/**
|
|
|
|
* EGroupware eTemplate2 - Readonly date-time_today WebComponent
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package api
|
|
|
|
* @link https://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
*/
|
|
|
|
|
2023-09-05 19:21:09 +02:00
|
|
|
import {formatDate, formatTime, parseDateTime} from "./Et2Date";
|
2022-02-03 22:58:56 +01:00
|
|
|
import {Et2DateReadonly} from "./Et2DateReadonly";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Widget displays date/time with different formatting relative to today
|
2022-05-05 11:38:33 +02:00
|
|
|
* If the date is today, we show just the time, otherwise just the date.
|
2022-02-03 22:58:56 +01:00
|
|
|
*/
|
|
|
|
export class Et2DateTimeToday extends Et2DateReadonly
|
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
this.parser = parseDateTime;
|
|
|
|
this.formatter = this.formatDateTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format date+time relative to "now"
|
2023-09-05 19:21:09 +02:00
|
|
|
* If the date is today, we show just the time. Otherwise, the date.
|
2022-02-03 22:58:56 +01:00
|
|
|
*
|
|
|
|
* @param {Date} date
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
formatDateTime(date : Date, options = {dateFormat: "", timeFormat: ""}) : string
|
|
|
|
{
|
|
|
|
let display = "";
|
|
|
|
// Today - just the time
|
|
|
|
if(formatDate(date, {dateFormat: 'Y-m-d'}) == formatDate(new Date(), {dateFormat: 'Y-m-d'}))
|
|
|
|
{
|
|
|
|
display = formatTime(date);
|
|
|
|
}
|
2022-05-05 11:38:33 +02:00
|
|
|
// Before today - just the date
|
2022-02-03 22:58:56 +01:00
|
|
|
else
|
|
|
|
{
|
2022-05-05 11:38:33 +02:00
|
|
|
display = formatDate(date);
|
2022-02-03 22:58:56 +01:00
|
|
|
}
|
|
|
|
return display;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this is a LitElement
|
2022-05-05 11:38:33 +02:00
|
|
|
customElements.define("et2-date-time-today", Et2DateTimeToday);
|