Skip to content

Commit 0faab65

Browse files
committed
fix(material): Fix Datepicker day behind
1 parent 7e6d394 commit 0faab65

File tree

12 files changed

+84
-139
lines changed

12 files changed

+84
-139
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "demo",
3-
"version": "13.1.2",
3+
"version": "13.1.3",
44
"author": "https://github.com/hamzahamidi/Angular6-json-schema-form/graphs/contributors",
55
"description": "Angular JSON Schema Form builder Demo",
66
"engines": {

projects/ajsf-bootstrap3/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ajsf/bootstrap3",
3-
"version": "0.5.1-beta.3",
3+
"version": "0.5.1-beta.4",
44
"description": "Angular JSON Schema Form builder using Bootstrap 3 UI",
55
"author": "https://github.com/hamzahamidi/ajsf/graphs/contributors",
66
"keywords": [
@@ -29,7 +29,7 @@
2929
"private": false,
3030
"dependencies": {
3131
"lodash-es": "~4.17.21",
32-
"@ajsf/core": "~0.5.1-beta.3",
32+
"@ajsf/core": "~0.5.1-beta.4",
3333
"tslib": "^2.0.0"
3434
},
3535
"peerDependencies": {

projects/ajsf-bootstrap4/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ajsf/bootstrap4",
3-
"version": "0.5.1-beta.3",
3+
"version": "0.5.1-beta.4",
44
"description": "Angular JSON Schema Form builder using Bootstrap 4 UI",
55
"author": "https://github.com/hamzahamidi/ajsf/graphs/contributors",
66
"keywords": [
@@ -29,7 +29,7 @@
2929
"private": false,
3030
"dependencies": {
3131
"lodash-es": "~4.17.21",
32-
"@ajsf/core": "~0.5.1-beta.3",
32+
"@ajsf/core": "~0.5.1-beta.4",
3333
"tslib": "^2.0.0"
3434
},
3535
"peerDependencies": {

projects/ajsf-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ajsf/core",
3-
"version": "0.5.1-beta.3",
3+
"version": "0.5.1-beta.4",
44
"description": "Angular JSON Schema Form builder core",
55
"author": "https://github.com/hamzahamidi/ajsf/graphs/contributors",
66
"keywords": [

projects/ajsf-core/src/lib/shared/date.functions.spec.ts

Lines changed: 0 additions & 68 deletions
This file was deleted.

projects/ajsf-core/src/lib/shared/date.functions.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

projects/ajsf-core/src/lib/shared/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,3 @@ export {
3838
export {
3939
buildLayout, buildLayoutFromSchema, mapLayout, getLayoutNode, buildTitleMap
4040
} from './layout.functions';
41-
42-
export { dateToString } from './date.functions';
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {
2+
toIsoString,
3+
toJavaScriptType,
4+
toSchemaType,
5+
} from "./validator.functions";
6+
7+
describe("Validator functions", () => {
8+
describe("toIsoString", () => {
9+
it("should work with timezone", () => {
10+
expect(toIsoString(new Date("05 October 2011 14:48 UTC"))).toEqual(
11+
"2011-10-05"
12+
);
13+
});
14+
});
15+
describe("toJavaScriptType", () => {
16+
it("Converts an input (probably string) value to a JavaScript primitive type 'string', 'number', 'boolean', or 'null' - before storing in a JSON object.", () => {
17+
expect(toJavaScriptType("10", "number")).toEqual(10);
18+
expect(toJavaScriptType("10", "integer")).toEqual(10);
19+
expect(toJavaScriptType(10, "integer")).toEqual(10);
20+
expect(toJavaScriptType(10, "string")).toEqual("10");
21+
expect(toJavaScriptType("10.5", "integer")).toEqual(null);
22+
expect(toJavaScriptType(10.5, "integer")).toEqual(null);
23+
});
24+
});
25+
describe("toSchemaType", () => {
26+
it("Number conversion examples", () => {
27+
expect(toSchemaType(10, ["number", "integer", "string"])).toEqual(10);
28+
expect(toSchemaType(10, ["number", "string"])).toEqual(10);
29+
expect(toSchemaType(10, ["string"])).toEqual("10");
30+
expect(toSchemaType(10.5, ["number", "integer", "string"])).toEqual(10.5);
31+
expect(toSchemaType(10.5, ["integer", "string"])).toEqual("10.5");
32+
expect(toSchemaType(10.5, ["integer"])).toEqual(10);
33+
});
34+
it("Boolean conversion examples", () => {
35+
expect(
36+
toSchemaType("1", ["integer", "number", "string", "boolean"])
37+
).toEqual("1");
38+
expect(toSchemaType("1", ["string", "boolean"])).toEqual("1");
39+
expect(toSchemaType("1", ["boolean"])).toEqual("1");
40+
expect(toSchemaType("true", ["number", "string", "boolean"])).toEqual(
41+
"true"
42+
);
43+
expect(toSchemaType("true", ["boolean"])).toEqual("true");
44+
expect(toSchemaType("true", ["number"])).toEqual(0);
45+
});
46+
it("string conversion examples", () => {
47+
expect(
48+
toSchemaType("1.58", ["boolean", "number", "integer", "string"])
49+
).toEqual("1.58");
50+
expect(toSchemaType("1.5", ["boolean", "number", "integer"])).toEqual(
51+
"1.5"
52+
);
53+
});
54+
});
55+
});

projects/ajsf-core/src/lib/shared/validator.functions.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,21 @@ export function isPrimitive(value) {
342342
isBoolean(value, 'strict') || value === null);
343343
}
344344

345+
/**
346+
*
347+
* @param date
348+
* @returns {string}
349+
* exmaple:
350+
* toDateString('2018-01-01') = '2018-01-01'
351+
* toDateString('2018-01-30T00:00:00.000Z') = '2018-01-30'
352+
*/
353+
export const toIsoString = (date: Date) => {
354+
const day = date.getDate();
355+
const month = date.getMonth() + 1;
356+
const year = date.getFullYear();
357+
return `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`;
358+
}
359+
345360
/**
346361
* 'toJavaScriptType' function
347362
*
@@ -388,7 +403,7 @@ export function toJavaScriptType(value, types, strictIntegers = true) {
388403
if (isString(value)) { return value; }
389404
// If value is a date, and types includes 'string',
390405
// convert the date to a string
391-
if (isDate(value)) { return value.toISOString().slice(0, 10); }
406+
if (isDate(value)) { return toIsoString(value); }
392407
if (isNumber(value)) { return value.toString(); }
393408
}
394409
// If value is a date, and types includes 'integer' or 'number',

0 commit comments

Comments
 (0)