Skip to content

Commit f08d07f

Browse files
committed
Validate date when editing
1 parent 6246dcf commit f08d07f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@stephenharris/task-cli",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "",
55
"main": "./index.js",
66
"bin": {

src/command/edit.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { stringify } from 'yaml'
55
import inquirer from "inquirer"
66
import {YAML} from "yaml-schema"
77
import { deepEqual } from "../lib/util";
8+
import moment from "moment";
89

910
const taskService = new TaskService(Disk.getStore())
1011

@@ -17,7 +18,11 @@ const editTask = (taskDetails: string, taskID: string): Promise<any> => {
1718
const yaml = new YAML(TaskSchema)
1819

1920
try {
20-
const t = yaml.parse(answer["task"])
21+
const t = yaml.parse(answer["task"]) as Task
22+
if(t.date && !moment(t.date).isValid()) {
23+
throw Error(`'${t.date}' is not a valid date`)
24+
}
25+
2126
return t;
2227
} catch (e: any) {
2328
console.log(chalk.red(`Error editing task: ${e.message}`));

0 commit comments

Comments
 (0)