Skip to content
Permalink
Browse files
feat(date input): create new component for date input (DSP-94) (#298)
* feat(date input): create new component for date input (ongoing)

* feat(date input): component for date input (ongoing)

* feat(date input): component for date input (ongoing)

* feat(date input): component for date input (ongoing)

* feat(date input): component for date input (ongoing)

* feat(date input): component for date input (ongoing)

* feat(date input): component for date input (ongoing)

* feat(date input): component for date input (ongoing)

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): component for date input (ongoing))

* feat(date input): move new date components to lib

* fix(date edit): make calendar update async

* refactor(viewer): remove check if a date can be edited

* feat(date input text): add Input for required validator

* feat(date edit): add Input for required validator

* feat(date edit): adjust day selection when changing month

* test(date edit): add spec

* test(date edit): add spec

* test(date edit): add spec

* test(date edit): add spec

* test(date edit): add spec

* test(date edit): add spec

* feat(date edit): reinit days after calendar change

* test(date edit): add spec

* feat(value service): move date calc logic to service

* test(date edit): add spec

* test(date edit): add spec

* test(date input text): add spec

* test(date input text): add spec

* test(date input text): add spec

* test(date input text): add spec

* test(date input text): add spec

* test(date input text): add spec

* test(date input text): add spectest(date input text): add spec

* test(date input text): add spec

* test(date input text): add spec

* test(date input text): fix CSS

* feat(value service): move date calc logic to service

* feat(value service): move date calc logic to service

* feat(viewer): handle Islamic date (no era)

* refactor(date edit): centralize logic for setting era

* feat(date input / edit): unsubscribe from valueChanges on com. destruction

* refactor(viewer): remove parameters

* refactor(viewer): remove injected service
  • Loading branch information
tobiasschweizer committed Jun 9, 2021
1 parent 90ad416 commit d23e844
Show file tree
Hide file tree
Showing 14 changed files with 2,015 additions and 240 deletions.
@@ -61,59 +61,6 @@ describe('ValueService', () => {

});

describe('isDateEditable', () => {

it('should determine if a given date or period is editable', () => {

expect(service.isDateEditable(new KnoraDate('GREGORIAN', 'CE', 2018, 5, 13))).toBe(true);

expect(service.isDateEditable(new KnoraDate('GREGORIAN', 'AD', 2018, 5, 13))).toBe(true);

// before common era
expect(service.isDateEditable(new KnoraDate('GREGORIAN', 'BCE', 2018, 5, 13))).toBe(false);

// before common era
expect(service.isDateEditable(new KnoraDate('GREGORIAN', 'BC', 2018, 5, 13))).toBe(false);

// month precision
expect(service.isDateEditable(new KnoraDate('GREGORIAN', 'CE', 2018, 5))).toBe(false);

// year precision
expect(service.isDateEditable(new KnoraDate('GREGORIAN', 'CE', 2018))).toBe(false);

expect(service.isDateEditable(new KnoraPeriod(
new KnoraDate('GREGORIAN', 'CE', 2018, 5, 13),
new KnoraDate('GREGORIAN', 'CE', 2019, 5, 13)
))).toBe(true);

// period starts with year precision
expect(service.isDateEditable(new KnoraPeriod(
new KnoraDate('GREGORIAN', 'CE', 2018),
new KnoraDate('GREGORIAN', 'CE', 2019, 5, 13)
))).toBe(false);

// period ends with year precision
expect(service.isDateEditable(new KnoraPeriod(
new KnoraDate('GREGORIAN', 'CE', 2018, 5, 13),
new KnoraDate('GREGORIAN', 'CE', 2019)
))).toBe(false);

// period starts with BCE date
expect(service.isDateEditable(new KnoraPeriod(
new KnoraDate('GREGORIAN', 'BCE', 2018, 5, 13),
new KnoraDate('GREGORIAN', 'CE', 2019, 5, 13)
))).toBe(false);

// period ends with BCE date
expect(service.isDateEditable(new KnoraPeriod(
new KnoraDate('GREGORIAN', 'CE', 2018, 5, 13),
new KnoraDate('GREGORIAN', 'BCE', 2019, 5, 13)
))).toBe(false);

});

});

describe('isReadOnly', () => {

it('should not mark a ReadIntValue as ReadOnly', () => {
@@ -186,26 +133,6 @@ describe('ValueService', () => {
expect(service.isReadOnly(valueClass, readStandoffLinkValue, resPropDef)).toBeTruthy();
});

it('should mark ReadDateValue with unsupported era as ReadOnly', done => {

MockResource.getTestThing().subscribe(res => {
const date: ReadDateValue =
res.getValuesAs('http://0.0.0.0:3333/ontology/0001/anything/v2#hasDate', ReadDateValue)[0];

date.date = new KnoraDate('GREGORIAN', 'BCE', 2019, 5, 13);

const resPropDef = new ResourcePropertyDefinition();
resPropDef.isEditable = true;

const valueClass = service.getValueTypeOrClass(date);
expect(service.isReadOnly(valueClass, date, resPropDef)).toBeTruthy();

done();

});

});

it('should not mark ReadDateValue with supported era as ReadOnly', done => {

MockResource.getTestThing().subscribe(res => {
@@ -226,26 +153,6 @@ describe('ValueService', () => {

});

it('should mark ReadDateValue with unsupported precision as ReadOnly', done => {

MockResource.getTestThing().subscribe(res => {
const date: ReadDateValue =
res.getValuesAs('http://0.0.0.0:3333/ontology/0001/anything/v2#hasDate', ReadDateValue)[0];

date.date = new KnoraDate('GREGORIAN', 'CE', 2019, 5);

const resPropDef = new ResourcePropertyDefinition();
resPropDef.isEditable = true;

const valueClass = service.getValueTypeOrClass(date);
expect(service.isReadOnly(valueClass, date, resPropDef)).toBeTruthy();

done();

});

});

it('should not mark ReadDateValue with supported precision as ReadOnly', done => {

MockResource.getTestThing().subscribe(res => {
@@ -313,4 +220,113 @@ describe('ValueService', () => {
});

});

describe('calculateDaysInMonth', () => {

it('should calculate the number of days in February in a leap year', () => {

expect(service.calculateDaysInMonth('GREGORIAN', 2020, 2)).toEqual(29);

});

it('should calculate the number of days in February in a non leap year', () => {

expect(service.calculateDaysInMonth('GREGORIAN', 2021, 2)).toEqual(28);

});

it('should calculate the number of days in March', () => {

expect(service.calculateDaysInMonth('GREGORIAN', 2021, 3)).toEqual(31);

});

});

describe('createJDNCalendarDateFromKnoraDate', () => {

it('should create a JDN calendar date from a Knora date with day precision in the Gregorian calendar', () => {

const calDateJDN = service.createJDNCalendarDateFromKnoraDate(new KnoraDate('GREGORIAN', 'CE', 2021, 3, 15));

const period = calDateJDN.toJDNPeriod();

expect(period.periodStart).toEqual(2459289);
expect(period.periodEnd).toEqual(2459289);

});

it('should create a JDN calendar date from a Knora date BCE with day precision in the Gregorian calendar', () => {

const calDateJDN = service.createJDNCalendarDateFromKnoraDate(new KnoraDate('GREGORIAN', 'BCE', 1, 1, 1));

const period = calDateJDN.toJDNPeriod();

expect(period.periodStart).toEqual(1721060);
expect(period.periodEnd).toEqual(1721060);

});

it('should create a JDN calendar date from a Knora date with day precision in the Julian calendar', () => {

const calDateJDN = service.createJDNCalendarDateFromKnoraDate(new KnoraDate('JULIAN', 'CE', 2021, 3, 15));

const period = calDateJDN.toJDNPeriod();

expect(period.periodStart).toEqual(2459302);
expect(period.periodEnd).toEqual(2459302);

});

it('should create a JDN calendar date from a Knora date with month precision in the Gregorian calendar', () => {

const calDateJDN = service.createJDNCalendarDateFromKnoraDate(new KnoraDate('GREGORIAN', 'CE', 2021, 3));

const period = calDateJDN.toJDNPeriod();

expect(period.periodStart).toEqual(2459275);
expect(period.periodEnd).toEqual(2459305);

});

it('should create a JDN calendar date from a Knora date with year precision in the Gregorian calendar', () => {

const calDateJDN = service.createJDNCalendarDateFromKnoraDate(new KnoraDate('GREGORIAN', 'CE', 2021));

const period = calDateJDN.toJDNPeriod();

expect(period.periodStart).toEqual(2459216);
expect(period.periodEnd).toEqual(2459580);

});

});

describe('convertHistoricalYearToAstronomicalYear', () => {

it('should convert the year 1 BCE to its astronomical representation', () => {

expect(service.convertHistoricalYearToAstronomicalYear(1, 'BCE', 'JULIAN')).toEqual(0);

});

it('should convert the year 2 BCE to its astronomical representation', () => {

expect(service.convertHistoricalYearToAstronomicalYear(2, 'BCE', 'JULIAN')).toEqual(-1);

});

it('should convert the year 1 CE to its astronomical representation', () => {

expect(service.convertHistoricalYearToAstronomicalYear(1, 'CE', 'JULIAN')).toEqual(1);

});

it('should convert the year 1 in the Islamic to its astronomical representation', () => {

expect(service.convertHistoricalYearToAstronomicalYear(1, 'noEra', 'ISLAMIC')).toEqual(1);

});

});
});

0 comments on commit d23e844

Please sign in to comment.