Skip to content

Commit

Permalink
✨ More Local Date/Time field changes
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Oct 24, 2023
1 parent de635aa commit 8f0e898
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
* @since 0.2.0
* @version 1.1.0
*/
var DateField = Function.inherits('Alchemy.Field', function Date(schema, name, options) {
Date.super.call(this, schema, name, options);
});
const DateField = Function.inherits('Alchemy.Field', 'Date');

/**
* Set the datatype name
Expand Down
15 changes: 13 additions & 2 deletions lib/app/helper_field/15-local_temporal_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@
* @since 1.3.20
* @version 1.3.20
*/
const LocalTemporal = Function.inherits('Alchemy.Field', 'LocalTemporal');
const LocalTemporal = Function.inherits('Alchemy.Field.Date', 'LocalTemporal');

/**
* Mark this class as being abstract
*
* @author Jelle De Loecker <jelle@elevenways.be>
* @since 1.3.20
* @version 1.3.20
*/
LocalTemporal.makeAbstractClass();

/**
* Cast the given value to this field's type for search in a db
Expand Down Expand Up @@ -80,7 +89,9 @@ LocalTemporal.setMethod(function _toDatasource(value, data, datasource, callback
LocalTemporal.setMethod(function _toApp(query, options, value, callback) {

if (value && typeof value == 'object') {
value = this.datasource.castToBigInt(value);
if (typeof value.getUTCDate != 'function') {
value = this.datasource.castToBigInt(value);
}
}

value = this.cast(value);
Expand Down
2 changes: 1 addition & 1 deletion lib/app/helper_field/local_date_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ LocalDate.setDatatype('date');
*/
LocalDate.setMethod(function cast(value) {

if (value == null) {
if (value == null || value === '') {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/app/helper_field/local_date_time_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ LocalDateTime.setDatatype('datetime');
*/
LocalDateTime.setMethod(function cast(value) {

if (value == null) {
if (value == null || value === '') {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/app/helper_field/local_time_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ LocalTime.setDatatype('time');
*/
LocalTime.setMethod(function cast(value) {

if (value == null) {
if (value == null || value === '') {
return null;
}

Expand Down
3 changes: 3 additions & 0 deletions lib/core/client_alchemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,9 @@ function getRoutesDict() {

// From here on, only client-side code is added
if (Blast.isBrowser) {
window.LocalDateTime = Blast.Classes.Develry.LocalDateTime;
window.LocalDate = Blast.Classes.Develry.LocalDate;
window.LocalTime = Blast.Classes.Develry.LocalTime;
window.alchemy = new Alchemy();
} else {
return;
Expand Down
11 changes: 11 additions & 0 deletions lib/init/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ DEFINE('Classes', Blast.Classes);
*/
DEFINE('Types', Blast.Types);

/**
* The new Local Date/Time classes
*
* @author Jelle De Loecker <jelle@elevenways.be>
* @since 1.3.20
* @version 1.3.20
*/
DEFINE('LocalDateTime', Blast.Classes.Develry.LocalDateTime);
DEFINE('LocalDate', Blast.Classes.Develry.LocalDate);
DEFINE('LocalTime', Blast.Classes.Develry.LocalTime);

/**
* Path to the directory of the server.js file
*
Expand Down
13 changes: 13 additions & 0 deletions test/04-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,19 @@ describe('Field.LocalTemporal', function() {
assert.strictEqual(found.length, 1);
assert.strictEqual(found[0].name, 'second');

let record = await LocalDtf.findByValues({
date : LocalDate.create('2022-09-11'),
});

assert.strictEqual(record?.name, 'second');

record = await LocalDtf.findByValues({
_id : record.$pk,
date : LocalDate.create('2022-09-11'),
});

assert.strictEqual(record?.name, 'second');

crit = LocalDtf.find();
crit.sort({date: 1});
crit.where('date').gt('2022-09-11');
Expand Down

0 comments on commit 8f0e898

Please sign in to comment.