Skip to main content

datetime

Introduction

Verify whether the parameter value is in date and time format

Example

Data Dictionary

hrm.sys_tasks Human Resources System - System Task List

| Column name | Data type | Not empty | Increment | Key | Description | |------------|-------------|----|----|----|------ --| | id | int(11) | yes | yes | primary key | - | | title | varchar(255) | Yes | - | - | Task title | | completed | tinyint(1) | - | - | - | Whether the task is completed | | start_time | datetime | - | - | - | Task start time | | end_time | datetime | - | - | - | Task end time |

  • Create hrm.sys_tasks task table

    DROP TABLE IF EXISTS hrm.sys_tasks;
    CREATE TABLE hrm.sys_tasks
    (
    id INT PRIMARY KEY AUTO_INCREMENT,
    title VARCHAR(255) NOT NULL,
    completed BOOLEAN COMMENT '0 not completed 1 completed data_type=bool',
    start_time DATETIME,
    end_time DATETIME
    );

In the table, the start_time and end_time fields are date and time types and need to comply with the date and time type specifications.

ask

POST http://127.0.0.1:21000
Content-Type: application/json;charset=utf-8
{
"jsonrpc": "2.0",
"method": "hrm.sysTasks.add",
"params": {
"title": "testing datatime type",
"completed": 1,
"startTime": "2023-11-41 08:00",
"endTime": "2023-11-41 08:00"
},
"id": "client-unique-request-id"
}

Response

It can be seen from the response result that luwak reported an error indicating that the values of the above startTime and endTime fields did not comply with the date type format specification and the operation was refused.

HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
{
"jsonrpc": "2.0",
"error": {
"code": -32602,
"message": "validating data type: endTime: 2023-11-41 08:00 does not validate as datetime;startTime: 2023-11-41 08:00 does not validate as datetime",
"data": {
"errorCode": "EU.Validator.DataTypeError",
"errorDetails": [
{
"field": "startTime",
"fieldValue": "2023-11-41 08:00",
"location": "hrm.sys_tasks",
"message": "startTime: 2023-11-41 08:00 does not validate as datetime",
"validator": "datetime"
},
{
"field": "endTime",
"fieldValue": "2023-11-41 08:00",
"location": "hrm.sys_tasks",
"message": "endTime: 2023-11-41 08:00 does not validate as datetime",
"validator": "datetime"
}
],
"errorMessage": "endTime: 2023-11-41 08:00 does not validate as datetime;startTime: 2023-11-41 08:00 does not validate as datetime"
}
},
"id": "client-unique-request-id"
}

Remarks: The above example was tested in Luwak 1.12.9.