Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time parse and default task name #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/taskParser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App} from 'obsidian';
import { App } from 'obsidian';
import UltimateTodoistSyncForObsidian from "../main";


Expand Down Expand Up @@ -46,6 +46,7 @@ interface todoistTaskObject {
const keywords = {
TODOIST_TAG: "#todoist",
DUE_DATE: "🗓️|📅|📆|🗓",
DUE_TIME: "⏰"
};

const REGEX = {
Expand All @@ -55,12 +56,14 @@ const REGEX = {
TODOIST_LINK:/\[link\]\(.*?\)/,
DUE_DATE_WITH_EMOJ: new RegExp(`(${keywords.DUE_DATE})\\s?\\d{4}-\\d{2}-\\d{2}`),
DUE_DATE : new RegExp(`(?:${keywords.DUE_DATE})\\s?(\\d{4}-\\d{2}-\\d{2})`),
DUE_TIME: new RegExp(`(?:${keywords.DUE_TIME})\\s?(\\d{2}:\\d{2})`),
PROJECT_NAME: /\[project::\s*(.*?)\]/,
TASK_CONTENT: {
REMOVE_PRIORITY: /\s!!([1-4])\s/,
REMOVE_TAGS: /(^|\s)(#[a-zA-Z\d\u4e00-\u9fa5-]+)/g,
REMOVE_SPACE: /^\s+|\s+$/g,
REMOVE_DATE: new RegExp(`(${keywords.DUE_DATE})\\s?\\d{4}-\\d{2}-\\d{2}`),
REMOVE_TIME: new RegExp(`(${keywords.DUE_TIME})\\s?\\d{2}:\\d{2}`),
REMOVE_INLINE_METADATA: /%%\[\w+::\s*\w+\]%%/,
REMOVE_CHECKBOX: /^(-|\*)\s+\[(x|X| )\]\s/,
REMOVE_CHECKBOX_WITH_INDENTATION: /^([ \t]*)?(-|\*)\s+\[(x|X| )\]\s/,
Expand Down Expand Up @@ -173,7 +176,11 @@ export class TaskParser {
}


const content = this.getTaskContentFromLineText(textWithoutIndentation)
let content = this.getTaskContentFromLineText(textWithoutIndentation)
if (content === "") {
// We use the obsidian's note as default task content
content = filepath.replace(/^.*[\\/]/, '').replace(".md","");
}
const isCompleted = this.isTaskCheckboxChecked(textWithoutIndentation)
let description = ""
const todoist_id = this.getTodoistIdFromLineText(textWithoutIndentation)
Expand Down Expand Up @@ -225,10 +232,16 @@ export class TaskParser {


getDueDateFromLineText(text: string) {
const result = REGEX.DUE_DATE.exec(text);
return result ? result[1] : null;
const date = REGEX.DUE_DATE.exec(text);
if (date === null){
return null;
}

const time = REGEX.DUE_TIME.exec(text);
return time
? date[1] + "T" + time[1]
: date[1] + "T08:00";
}



getProjectNameFromLineText(text:string){
Expand Down Expand Up @@ -281,6 +294,7 @@ export class TaskParser {
.replace(REGEX.TASK_CONTENT.REMOVE_PRIORITY," ") //priority 前后必须都有空格,
.replace(REGEX.TASK_CONTENT.REMOVE_TAGS,"")
.replace(REGEX.TASK_CONTENT.REMOVE_DATE,"")
.replace(REGEX.TASK_CONTENT.REMOVE_TIME,"")
.replace(REGEX.TASK_CONTENT.REMOVE_CHECKBOX,"")
.replace(REGEX.TASK_CONTENT.REMOVE_CHECKBOX_WITH_INDENTATION,"")
.replace(REGEX.TASK_CONTENT.REMOVE_SPACE,"")
Expand Down Expand Up @@ -486,7 +500,7 @@ export class TaskParser {
if(localDateString === null){
return null
}
localDateString = localDateString + "T08:00";
localDateString = localDateString;
let localDateObj = new Date(localDateString);
let ISOString = localDateObj.toISOString()
return(ISOString);
Expand All @@ -506,7 +520,7 @@ export class TaskParser {
if(localDateString === null){
return null
}
localDateString = localDateString + "T08:00";
localDateString = localDateString;
let localDateObj = new Date(localDateString);
let ISOString = localDateObj.toISOString()
let utcDateString = ISOString.slice(0,10)
Expand Down
1 change: 0 additions & 1 deletion src/todoistRestAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ function localDateStringToUTCDatetimeString(localDateString:string) {
if(localDateString === null){
return null
}
localDateString = localDateString + "T08:00";
let localDateObj = new Date(localDateString);
let ISOString = localDateObj.toISOString()
return(ISOString);
Expand Down