Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kup-dates: isValid() method: check if converted date is the same of input string #2087

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ import {
FChipType,
} from '../../f-components/f-chip/f-chip-declarations';
import { KupLanguageGeneric } from '../../managers/kup-language/kup-language-declarations';
import { KupDatesLocales } from '../../managers/kup-dates/kup-dates-declarations';
import {
KupDatesFormats,
KupDatesLocales,
} from '../../managers/kup-dates/kup-dates-declarations';
import {
KupDataColumn,
KupDataRow,
Expand Down Expand Up @@ -445,11 +448,11 @@ export class KupCalendar {
if (startCell && endCell) {
const dayjsStart = this.kupManager.dates.toDayjs(
startCell.value,
'HH:mm:ss'
KupDatesFormats.ISO_TIME
);
const dayjsEnd = this.kupManager.dates.toDayjs(
endCell.value,
'HH:mm:ss'
KupDatesFormats.ISO_TIME
);

startDate = startDate.hour(dayjsStart.hour());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ function refresh(component: KupCard) {

function onCalendarMonthYearItemClick(component: KupCard, value: string) {
let d: Date;
if (dom.ketchup.dates.isValid(value, KupDatesFormats.ISO_DATE)) {
if (dom.ketchup.dates.isIsoDate(value)) {
d = new Date(value);
} else {
d = new Date();
Expand All @@ -581,7 +581,7 @@ function onCalendarMonthYearItemClick(component: KupCard, value: string) {

function onCalendarItemClick(component: KupCard, value: string) {
let d: Date;
if (dom.ketchup.dates.isValid(value, KupDatesFormats.ISO_DATE)) {
if (dom.ketchup.dates.isIsoDate(value)) {
d = new Date(value);
} else {
d = new Date();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ChartSerie } from './kup-chart-declarations';
import { getColumnByName } from '../../utils/cell-utils';
import { KupObjects } from '../../managers/kup-objects/kup-objects';
import { KupDates } from '../../managers/kup-dates/kup-dates';
import { KupDatesNormalize } from '../../managers/kup-dates/kup-dates-declarations';
import { KupDatesFormats } from '../../managers/kup-dates/kup-dates-declarations';
import {
KupDataColumn,
KupDataDataset,
Expand Down Expand Up @@ -95,7 +95,7 @@ export const convertRows = (
} else if (kupObjects.isTime(cell.obj)) {
const datetime = kupDates.normalize(
cell.obj.k,
KupDatesNormalize.TIME
KupDatesFormats.ISO_TIME
);
currentRow.push(datetime.toDate());
if (addMark) {
Expand All @@ -104,7 +104,7 @@ export const convertRows = (
} else if (kupObjects.isTimestamp(cell.obj)) {
const datetime = kupDates.normalize(
cell.obj.k,
KupDatesNormalize.TIMESTAMP
KupDatesFormats.ISO_DATE_TIME
);
currentRow.push(datetime.toDate());
if (addMark) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,11 @@ function updateGroupTotal(
cell.value &&
dom.ketchup.objects.isDate(cell.obj)
) {
const cellValue = dom.ketchup.dates.toDayjs(cell.value);
if (dom.ketchup.dates.isValid(cellValue)) {
if (
dom.ketchup.dates.isValidFormattedStringDate(
cell.value
)
) {
const currentMinValue = groupRow.group.totals[key];
if (currentMinValue) {
let moments = [];
Expand Down Expand Up @@ -554,8 +557,11 @@ function updateGroupTotal(
cell.value &&
dom.ketchup.objects.isDate(cell.obj)
) {
const cellValue = dom.ketchup.dates.toDayjs(cell.value);
if (dom.ketchup.dates.isValid(cellValue)) {
if (
dom.ketchup.dates.isValidFormattedStringDate(
cell.value
)
) {
const currentMaxValue = groupRow.group.totals[key];
if (currentMaxValue) {
let moments = [];
Expand Down Expand Up @@ -870,12 +876,14 @@ export function calcTotals(
if (dateColumns.indexOf(key) == -1) {
dateColumns.push(key);
}
const momentValue = dom.ketchup.dates.toDayjs(
cell.value
);
if (dom.ketchup.dates.isValid(momentValue)) {
const cellValue =
dom.ketchup.dates.toDate(momentValue);
if (
dom.ketchup.dates.isValidFormattedStringDate(
cell.value
)
) {
const cellValue = dom.ketchup.dates.toDate(
dom.ketchup.dates.toDayjs(cell.value)
);
const currentFooterValue = footerRow[key]
? dom.ketchup.dates.toDate(
dom.ketchup.dates.toDayjs(footerRow[key])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1796,12 +1796,7 @@ export class KupDataTable {
if (!totalValue) {
totalValue = row.group.id;
}
if (
this.#kupManager.dates.isValid(
totalValue,
KupDatesFormats.ISO_DATE
)
) {
if (this.#kupManager.dates.isIsoDate(totalValue)) {
totalValue = this.#kupManager.dates.format(totalValue);
}
cells[id] = {
Expand Down Expand Up @@ -4880,10 +4875,7 @@ export class KupDataTable {
if (this.#kupManager.objects.isDate(column.obj)) {
if (totalValue) {
if (
this.#kupManager.dates.isValid(
totalValue,
KupDatesFormats.ISO_DATE
)
this.#kupManager.dates.isIsoDate(totalValue)
) {
value =
this.#kupManager.dates.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ import {
} from './kup-date-picker-declarations';
import { KupDebugCategory } from '../../managers/kup-debug/kup-debug-declarations';
import { componentWrapperId } from '../../variables/GenericVariables';
import {
KupDatesFormats,
KupDatesNormalize,
} from '../../managers/kup-dates/kup-dates-declarations';
import { KupDatesFormats } from '../../managers/kup-dates/kup-dates-declarations';
import { FTextField } from '../../f-components/f-text-field/f-text-field';
import { FTextFieldMDC } from '../../f-components/f-text-field/f-text-field-mdc';
import { FTextFieldProps } from '../../f-components/f-text-field/f-text-field-declarations';
Expand Down Expand Up @@ -404,19 +401,20 @@ export class KupDatePicker {
}
} else if (this.isAlphanumeric(eventDetailValue)) {
/** donothing */
} else if (this.kupManager.dates.isValid(eventDetailValue)) {
} else if (
this.kupManager.dates.isValidFormattedStringDate(eventDetailValue)
) {
newValue = this.kupManager.dates.format(
this.kupManager.dates.normalize(
eventDetailValue,
KupDatesNormalize.DATE
),
this.kupManager.dates.normalize(eventDetailValue),
KupDatesFormats.ISO_DATE
);
this.refreshPickerComponentValue(newValue);
if (isOnInputEvent != true) {
this.ISOvalue = newValue;
this.notISOvalue = '';
}
} else {
/** donothing */
}

if (newValue != null && eventToRaise) {
Expand All @@ -432,7 +430,7 @@ export class KupDatePicker {
return;
}
let d: Date;
if (this.kupManager.dates.isValid(value, KupDatesFormats.ISO_DATE)) {
if (this.kupManager.dates.isIsoDate(value)) {
d = new Date(value);
} else {
d = new Date();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ export function sanitizeAllDates(
let sanitizedHourValues = [];
if (startHourCell && endHourCell) {
if (isAtLeastOneHourValid(startHourCell, endHourCell)) {
sanitizedHourValues = sanitizeHours(
startHourCell,
endHourCell
);
sanitizedHourValues = sanitizeHours(startHourCell, endHourCell);
} else {
sanitizedSecDateValues = [...sanitizedDateValues];
}
Expand All @@ -58,7 +55,7 @@ export function sanitizeAllDates(
dateValues: sanitizedDateValues,
secDateValues: sanitizedSecDateValues,
hourValues: sanitizedHourValues,
secHourValues: sanitizedSecHourValues
secHourValues: sanitizedSecHourValues,
};
}

Expand Down Expand Up @@ -97,13 +94,14 @@ function sanitizeHours(
function isDateValid(dateCell: KupDataCell) {
return (
kupManager.objects.isDate(dateCell.obj) &&
kupManager.dates.isValid(dateCell.value, KupDatesFormats.ISO_DATE)
kupManager.dates.isIsoDate(dateCell.value)
);
}

function isHourValid(dateCell: KupDataCell) {
return (
kupManager.objects.isTime(dateCell.obj) || kupManager.objects.isTimeWithSeconds(dateCell.obj)
kupManager.objects.isTime(dateCell.obj) ||
kupManager.objects.isTimeWithSeconds(dateCell.obj)
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
/**
* Normalization types.
*/
export enum KupDatesNormalize {
DATE = 'date',
TIME = 'time',
TIMESTAMP = 'timestamp',
}

/**
* Supported locales.
*/
Expand Down
Loading