Skip to content
Draft
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ publishing {
tasks.register( 'pnpmCheck', PnpmTask ) {
dependsOn tasks.named( 'pnpmInstall' )
args = ['run', 'check']
outputs.cacheIf { false }
outputs.upToDateWhen { false }
}

tasks.named( 'check' ).configure {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"jquery-simulate": "^1.0.2",
"jquery-ui": "^1.14.1",
"mousetrap": "^1.6.5",
"q": "^1.5.1"
"q": "^1.5.1",
"dayjs": "^1.11.19"
},
"devDependencies": {
"@enonic/eslint-config": "^2.2.1",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/main/resources/assets/admin/common/js/data/Property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {PropertyValueChangedEvent} from './PropertyValueChangedEvent';
import {assertNotNull} from '../util/Assert';
import {ValueTypes} from './ValueTypes';
import {ValueType} from './ValueType';
import {Instant} from '../util/Instant';

/**
* A Property has a [[name]] and a [[value]],
Expand Down Expand Up @@ -239,6 +240,10 @@ export class Property
return this.value.getBinaryReference();
}

getInstant(): Instant {
return this.value.getInstant();
}

equals(o: Equitable): boolean {

if (!ObjectHelper.iFrameSafeInstanceOf(o, Property)) {
Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/assets/admin/common/js/data/Value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import {Link} from '../util/Link';
import {PropertySet} from './PropertySet';
import {ValueType} from './ValueType';
import {Typable} from './Typable';
import {Instant} from '../util/Instant';

export type ValueData = string | number | boolean | PropertySet | Reference | BinaryReference | GeoPoint | Date | DateTime | LocalDate | LocalDateTime | LocalTime | Link;
export type ValueData = string | number | boolean | PropertySet | Reference | BinaryReference | GeoPoint | Date | Instant | DateTime | LocalDate | LocalDateTime | LocalTime | Link;

export class Value
implements Equitable, Cloneable, Typable {
Expand Down Expand Up @@ -145,6 +146,13 @@ export class Value
return this.value as Link;
}

getInstant(): Instant {
if (this.isNull()) {
return null;
}
return this.value as Instant;
}

equals(o: Equitable): boolean {

if (!ObjectHelper.iFrameSafeInstanceOf(o, Value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export class ValueTypeConverter {
return ValueTypeConverter.convertToReference(value);
} else if (toType === ValueTypes.BINARY_REFERENCE) {
return ValueTypeConverter.convertToBinaryReference(value);
} else if (toType === ValueTypes.INSTANT) {
return ValueTypeConverter.convertToInstant(value);
}

throw Error(`Unknown ValueType: ${toType.toString()}`);
Expand Down Expand Up @@ -153,14 +155,30 @@ export class ValueTypeConverter {
if (value.getType() === ValueTypes.STRING && ValueTypes.DATE_TIME.isConvertible(value.getString())) { // from string
return ValueTypes.DATE_TIME.newValue(value.getString());
} else if (value.getType() === ValueTypes.LOCAL_DATE && value.isNotNull()) { // from LocalDate
return ValueTypes.DATE_TIME.newValue(value.getString() + 'T00:00:00+00:00');
return ValueTypes.DATE_TIME.newValue(`${value.getString()}T00:00:00`);
} else if (value.getType() === ValueTypes.LOCAL_DATE_TIME && value.isNotNull()) { // from LocalDateTime
let dateTime = value.getString();
return ValueTypes.DATE_TIME.newValue(dateTime);
}
return ValueTypes.DATE_TIME.newNullValue();
}

private static convertToInstant(value: Value): Value {
if (value.getType() === ValueTypes.STRING && ValueTypes.INSTANT.isConvertible(value.getString())) { // from string
return ValueTypes.INSTANT.newValue(value.getString());
} else if (value.getType() === ValueTypes.LOCAL_DATE && value.isNotNull()) { // from LocalDate
return ValueTypes.INSTANT.newValue(`${value.getString()}T00:00:00Z`);
} else if (value.getType() === ValueTypes.LOCAL_DATE_TIME && value.isNotNull()) { // from LocalDateTime
const localDateTime = new Date(value.getString());
return ValueTypes.INSTANT.newValue(localDateTime.toISOString());
} else if (value.getType() === ValueTypes.DATE_TIME && value.isNotNull()) {
const dateTime = new Date(value.getString());
return ValueTypes.INSTANT.newValue(dateTime.toISOString());
} else {
return ValueTypes.INSTANT.newNullValue();
}
}

private static convertToLocalTime(value: Value): Value {
if (value.getType() === ValueTypes.STRING && ValueTypes.LOCAL_TIME.isConvertible(value.getString())) { // from string
return ValueTypes.LOCAL_TIME.newValue(value.getString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {DateTime} from '../util/DateTime';
import {ObjectHelper} from '../ObjectHelper';
import {StringHelper} from '../util/StringHelper';
import {ValueType} from './ValueType';
import {Value} from './Value';
import {DateTime} from '../util/DateTime';

export class ValueTypeDateTime
extends ValueType {
Expand All @@ -22,10 +22,7 @@ export class ValueTypeDateTime
if (StringHelper.isBlank(value)) {
return false;
}
// 2010-01-01T10:55:00+01:00
if (value.length < 19) {
return false;
}

return this.isValid(value);
}

Expand All @@ -40,7 +37,7 @@ export class ValueTypeDateTime
return new Value(date, this);
}

// 2010-01-01T10:55:00+01:00
// 2010-01-01T10:55:00
toJsonValue(value: Value): string {
return value.isNull() ? null : value.getDateTime().toString();
}
Expand All @@ -52,5 +49,4 @@ export class ValueTypeDateTime
valueEquals(a: DateTime, b: DateTime): boolean {
return ObjectHelper.equals(a, b);
}

}
49 changes: 49 additions & 0 deletions src/main/resources/assets/admin/common/js/data/ValueTypeInstant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {Instant} from '../util/Instant';
import {ObjectHelper} from '../ObjectHelper';
import {StringHelper} from '../util/StringHelper';
import {ValueType} from './ValueType';
import {Value} from './Value';

export class ValueTypeInstant
extends ValueType {

constructor() {
super('Instant');
}

isValid(value: any): boolean {
if (ObjectHelper.iFrameSafeInstanceOf(value, Instant)) {
return true;
}

return Instant.isValidInstant(value);
}

isConvertible(value: string): boolean {
if (StringHelper.isBlank(value)) {
return false;
}

return this.isValid(value);
}

newValue(value: string): Value {
if (!value || !this.isConvertible(value)) {
return this.newNullValue();
}
const date: Instant = Instant.fromString(value);
return new Value(date, this);
}

toJsonValue(value: Value): string {
return value.isNull() ? null : this.valueToString(value);
}

valueToString(value: Value): string {
return value.getInstant().toString();
}

valueEquals(a: Instant, b: Instant): boolean {
return ObjectHelper.equals(a, b);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ export class ValueTypeLocalDateTime
if (StringHelper.isBlank(value)) {
return false;
}
// 2010-01-01T10:55:00
if (value.length !== 19) {
return false;
}

return this.isValid(value);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/assets/admin/common/js/data/ValueTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {ValueTypeGeoPoint} from './ValueTypeGeoPoint';
import {ValueTypeReference} from './ValueTypeReference';
import {ValueTypeBinaryReference} from './ValueTypeBinaryReference';
import {ValueType} from './ValueType';
import {ValueTypeInstant} from './ValueTypeInstant';

export class ValueTypes {

Expand Down Expand Up @@ -44,6 +45,8 @@ export class ValueTypes {

static BINARY_REFERENCE: ValueTypeBinaryReference = new ValueTypeBinaryReference();

static INSTANT: ValueTypeInstant = new ValueTypeInstant();

static ALL: ValueType[] = [
ValueTypes.DATA,
ValueTypes.STRING,
Expand All @@ -58,6 +61,7 @@ export class ValueTypes {
ValueTypes.GEO_POINT,
ValueTypes.REFERENCE,
ValueTypes.BINARY_REFERENCE,
ValueTypes.INSTANT,
];

public static fromName(name: string): ValueType {
Expand Down
Loading