mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-23 07:09:20 +01:00
Add Et2DateTimeToday
This commit is contained in:
parent
b91f66c629
commit
28eb3fdd80
52
api/js/etemplate/Et2Date/Et2DateTimeToday.ts
Normal file
52
api/js/etemplate/Et2Date/Et2DateTimeToday.ts
Normal file
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
import {formatDate, formatDateTime, formatTime, parseDateTime} from "./Et2Date";
|
||||
import {Et2DateReadonly} from "./Et2DateReadonly";
|
||||
|
||||
/**
|
||||
* Widget displays date/time with different formatting relative to today
|
||||
* If the date is today, we show just the time. Otherwise, full date + time.
|
||||
*/
|
||||
export class Et2DateTimeToday extends Et2DateReadonly
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
this.parser = parseDateTime;
|
||||
this.formatter = this.formatDateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format date+time relative to "now"
|
||||
* If the date is today, we show just the time. Otherwise, the date and time.
|
||||
*
|
||||
* @param {Date} date
|
||||
* @param {import('@lion/localize/types/LocalizeMixinTypes').FormatDateOptions} [options] Intl options are available
|
||||
* @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);
|
||||
}
|
||||
// Before today - date and time
|
||||
else
|
||||
{
|
||||
display = formatDateTime(date);
|
||||
}
|
||||
return display;
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-ignore TypeScript is not recognizing that this is a LitElement
|
||||
customElements.define("et2-date-time_today", Et2DateTimeToday);
|
@ -32,6 +32,7 @@ import './Et2Date/Et2DateReadonly';
|
||||
import './Et2Date/Et2DateSinceReadonly';
|
||||
import './Et2Date/Et2DateTime';
|
||||
import './Et2Date/Et2DateTimeReadonly';
|
||||
import './Et2Date/Et2DateTimeToday';
|
||||
import './Et2Description/Et2Description';
|
||||
import './Et2Select/Et2Select';
|
||||
import './Et2Select/Et2SelectAccount';
|
||||
|
Loading…
Reference in New Issue
Block a user