How to use the @nakedobjects/restful-objects.toDateString function in @nakedobjects/restful-objects

To help you get started, we’ve selected a few @nakedobjects/restful-objects examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NakedObjectsGroup / NakedObjectsFramework / Spa2 / nakedobjectsspa / cicero / src / cicero-commands / enter.ts View on Github external
private handleFreeForm(field: Ro.IField, fieldEntry: string) {
        if (field.isScalar()) {

            const mandatoryError = validateMandatory(field, fieldEntry);

            if (mandatoryError) {
                return this.returnResult('', this.validationMessage(mandatoryError, new Ro.Value(''), field.extensions().friendlyName()));
            }

            let value = new Ro.Value(fieldEntry);
            if (Ro.isDateOrDateTime(field)) {
                const dt = validateDate(fieldEntry, supportedDateFormats);

                if (dt) {
                    value = new Ro.Value(Ro.toDateString(dt.toDate()));
                }
            }

            // if optional but empty always valid
            if (fieldEntry != null && fieldEntry !== '') {

                const remoteMask = field.extensions().mask();
                const localFilter = this.mask.toLocalFilter(remoteMask, field.extensions().format()!);

                const validateError = validateMandatoryAgainstType(field, fieldEntry, localFilter);

                if (validateError) {
                    return this.returnResult('', this.validationMessage(validateError, value, field.extensions().friendlyName()));
                }
            }
github NakedObjectsGroup / NakedObjectsFramework / Spa2 / nakedobjectsspa / cicero / src / validate.ts View on Github external
export function validateDateFormat(model: Models.IHasExtensions, newValue: Date | string, filter: ILocalFilter): string {
    const range = model.extensions().range();
    const newDate = (newValue instanceof Date) ? newValue : getDate(newValue);

    if (range && newDate) {
        const min = range.min ? getDate(range.min as string) : null;
        const max = range.max ? getDate(range.max as string) : null;

        if (min && newDate < min) {
            return Msg.outOfRange(Models.toDateString(newDate), Models.getUtcDate(range.min as string), Models.getUtcDate(range.max as string), filter);
        }

        if (max && newDate > max) {
            return Msg.outOfRange(Models.toDateString(newDate), Models.getUtcDate(range.min as string), Models.getUtcDate(range.max as string), filter);
        }
    }

    return '';
}
github NakedObjectsGroup / NakedObjectsFramework / Spa2 / nakedobjectsspa / cicero / src / validate.ts View on Github external
export function validateDateFormat(model: Models.IHasExtensions, newValue: Date | string, filter: ILocalFilter): string {
    const range = model.extensions().range();
    const newDate = (newValue instanceof Date) ? newValue : getDate(newValue);

    if (range && newDate) {
        const min = range.min ? getDate(range.min as string) : null;
        const max = range.max ? getDate(range.max as string) : null;

        if (min && newDate < min) {
            return Msg.outOfRange(Models.toDateString(newDate), Models.getUtcDate(range.min as string), Models.getUtcDate(range.max as string), filter);
        }

        if (max && newDate > max) {
            return Msg.outOfRange(Models.toDateString(newDate), Models.getUtcDate(range.min as string), Models.getUtcDate(range.max as string), filter);
        }
    }

    return '';
}
github NakedObjectsGroup / NakedObjectsFramework / Spa2 / nakedobjectsspa / view-models / src / helpers-view-models.ts View on Github external
export function setScalarValueInView(vm: { value: string | number | boolean | Date | null }, propertyRep: Ro.PropertyMember, value: Ro.Value) {
    if (Ro.isDate(propertyRep)) {
        const date = Ro.toUtcDate(value);
        vm.value = date ? Ro.toDateString(date) : '';
    } else if (Ro.isDateTime(propertyRep)) {
        const date = Ro.toUtcDate(value);
        vm.value = date ? Ro.toDateTimeString(date) : '';
    } else if (Ro.isTime(propertyRep)) {
        const time = Ro.toTime(value);
        vm.value = time ? Ro.toTimeString(time) : '';
    } else {
        vm.value = value.scalar();
    }
}