Skip to content

Commit bb65c44

Browse files
committed
v4.17.3: simplified-date
1 parent ce938d2 commit bb65c44

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@signal24/vue-foundation",
33
"type": "module",
4-
"version": "4.17.2",
4+
"version": "4.17.3",
55
"description": "Common components, directives, and helpers for Vue 3 apps",
66
"module": "./dist/vue-foundation.es.js",
77
"exports": {

src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ interface IOptions {
22
unhandledErrorSupportText: string;
33
errorHandler: (err: Error) => void;
44
defaultDateFormat: string;
5-
defaultDateTimeFormat: string;
5+
defaultTimeFormat: string;
66
}
77

88
export const VfOptions: IOptions = {
99
unhandledErrorSupportText: 'please contact support',
1010
errorHandler: err => console.error('Unhandled error:', err),
1111
defaultDateFormat: 'M/d/yy',
12-
defaultDateTimeFormat: 'M/d/yy H:mm'
12+
defaultTimeFormat: 'H:mm'
1313
};
1414

1515
export function configureVf(options: Partial<IOptions>) {

src/directives/datetime.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { format } from 'date-fns';
2+
import { compact } from 'lodash';
23
import type { DirectiveBinding, ObjectDirective } from 'vue';
34

45
import { VfOptions } from '../config';
@@ -28,20 +29,36 @@ function getDateTimeValue(el: HTMLElement, binding: DirectiveBinding<string>) {
2829
}
2930

3031
let formatSpec = el.attributes.getNamedItem('format')?.value;
32+
const isDateOnly = el.attributes.getNamedItem('date-only') !== null;
3133

3234
if (!formatSpec && el.attributes.getNamedItem('relative-date') !== null) {
3335
const now = new Date();
34-
if (now.getFullYear() == theDate.getFullYear() && now.getMonth() == theDate.getMonth() && now.getDate() == theDate.getDate()) {
35-
prefix = 'at';
36+
if (now.getFullYear() === theDate.getFullYear() && now.getMonth() === theDate.getMonth() && now.getDate() === theDate.getDate()) {
37+
prefix = 'at'; // ???
3638
formatSpec = 'HH:mm';
3739
}
3840
}
3941

42+
if (!formatSpec && el.attributes.getNamedItem('simplified-date') !== null) {
43+
let dateSpec: string | null = null;
44+
const now = new Date();
45+
if (now.getFullYear() === theDate.getFullYear()) {
46+
if (now.getMonth() !== theDate.getMonth() || now.getDate() !== theDate.getDate()) {
47+
dateSpec = 'M/d';
48+
}
49+
} else {
50+
dateSpec = 'M/d/YY';
51+
}
52+
53+
const timeSpec = isDateOnly ? null : VfOptions.defaultTimeFormat;
54+
formatSpec = compact([dateSpec, timeSpec]).join(' ');
55+
}
56+
4057
if (!formatSpec) {
41-
if (el.attributes.getNamedItem('date-only') !== null) {
58+
if (isDateOnly) {
4259
formatSpec = VfOptions.defaultDateFormat;
4360
} else {
44-
formatSpec = VfOptions.defaultDateTimeFormat;
61+
formatSpec = `${VfOptions.defaultDateFormat} ${VfOptions.defaultTimeFormat}`;
4562
}
4663
}
4764

0 commit comments

Comments
 (0)