@dasch-swiss/dsp-js
Version:
TypeScript client library for DSP-API
160 lines • 5.45 kB
JavaScript
import { __decorate, __metadata } from "tslib";
import { JsonObject, JsonProperty } from 'json2typescript';
import { Constants } from '../../../Constants';
import { ReadValue } from './read-value';
/**
* @category Internal
*/
let ParseReadDateValue = class ParseReadDateValue extends ReadValue {
constructor() {
super(...arguments);
this.datestring = '';
this.calendar = '';
this.startDay = undefined;
this.startMonth = undefined;
this.startYear = 0;
this.startEra = undefined;
this.endDay = undefined;
this.endMonth = undefined;
this.endYear = 0;
this.endEra = undefined;
}
};
__decorate([
JsonProperty(Constants.ValueAsString, String),
__metadata("design:type", Object)
], ParseReadDateValue.prototype, "datestring", void 0);
__decorate([
JsonProperty(Constants.DateValueHasCalendar, String),
__metadata("design:type", Object)
], ParseReadDateValue.prototype, "calendar", void 0);
__decorate([
JsonProperty(Constants.DateValueHasStartDay, Number, true),
__metadata("design:type", Number)
], ParseReadDateValue.prototype, "startDay", void 0);
__decorate([
JsonProperty(Constants.DateValueHasStartMonth, Number, true),
__metadata("design:type", Number)
], ParseReadDateValue.prototype, "startMonth", void 0);
__decorate([
JsonProperty(Constants.DateValueHasStartYear, Number),
__metadata("design:type", Object)
], ParseReadDateValue.prototype, "startYear", void 0);
__decorate([
JsonProperty(Constants.DateValueHasStartEra, String, true),
__metadata("design:type", String)
], ParseReadDateValue.prototype, "startEra", void 0);
__decorate([
JsonProperty(Constants.DateValueHasEndDay, Number, true),
__metadata("design:type", Number)
], ParseReadDateValue.prototype, "endDay", void 0);
__decorate([
JsonProperty(Constants.DateValueHasEndMonth, Number, true),
__metadata("design:type", Number)
], ParseReadDateValue.prototype, "endMonth", void 0);
__decorate([
JsonProperty(Constants.DateValueHasEndYear, Number),
__metadata("design:type", Object)
], ParseReadDateValue.prototype, "endYear", void 0);
__decorate([
JsonProperty(Constants.DateValueHasEndEra, String, true),
__metadata("design:type", String)
], ParseReadDateValue.prototype, "endEra", void 0);
ParseReadDateValue = __decorate([
JsonObject('ReadDateValue')
], ParseReadDateValue);
export { ParseReadDateValue };
/**
* Precision of a date.
*
* @category Model V2
*/
export var Precision;
(function (Precision) {
/**
* Year precision (first to last day of the year).
*/
Precision[Precision["yearPrecision"] = 0] = "yearPrecision";
/**
* Month precision (first to last day of the month).
*/
Precision[Precision["monthPrecision"] = 1] = "monthPrecision";
/**
* Day precision.
*/
Precision[Precision["dayPrecision"] = 2] = "dayPrecision";
})(Precision || (Precision = {}));
/**
* Represents a Salsah date object with a precision information.
*
* @category Model V2
*/
export class KnoraDate {
// TODO: support instantiation of a JDNConvertibleCalendar subclass, e.g., GregorianCalendarDate
static { this.separator = '-'; }
constructor(calendar, era, year, month, day) {
this.calendar = calendar;
this.era = era;
this.year = year;
this.month = month;
this.day = day;
if (this.month === undefined) {
// year precision
this.precision = Precision.yearPrecision;
}
else if (this.day === undefined) {
// month precision
this.precision = Precision.monthPrecision;
}
else {
// day precision
this.precision = Precision.dayPrecision;
}
}
}
/**
* Represents a period (with start date and end date).
*
* @category Model V2
*/
export class KnoraPeriod {
constructor(start, end) {
this.start = start;
this.end = end;
}
}
/**
* @category Model V2
*/
export class ReadDateValue extends ReadValue {
constructor(date) {
super(date.id, date.type, date.attachedToUser, date.arkUrl, date.versionArkUrl, date.valueCreationDate, date.hasPermissions, date.userHasPermission, date.uuid, date.propertyLabel, date.propertyComment, date.property, date.datestring, date.valueHasComment);
if (date.startYear === date.endYear &&
date.startMonth === date.endMonth &&
date.startDay === date.endDay &&
date.startEra === date.endEra) {
// single date
this.date = new KnoraDate(date.calendar, this.handleEra(date.startEra), date.startYear, date.startMonth, date.startDay);
}
else {
// date period
this.date = new KnoraPeriod(new KnoraDate(date.calendar, this.handleEra(date.startEra), date.startYear, date.startMonth, date.startDay), new KnoraDate(date.calendar, this.handleEra(date.endEra), date.endYear, date.endMonth, date.endDay));
}
}
/**
* Determines if an era is given.
* Returns "noEra" in case none is given (the given calendar date does not have an era).
*
* @param era given era, if any.
*/
handleEra(era) {
// determine era
if (era !== undefined) {
return era;
}
else {
return 'noEra';
}
}
}
//# sourceMappingURL=read-date-value.js.map