diff --git a/timer.v b/timer.v index 023e640..07fd716 100644 --- a/timer.v +++ b/timer.v @@ -4,6 +4,7 @@ import time import gg import gx import os +import strings const ( time_cfg = gx.TextCfg{ @@ -192,3 +193,50 @@ fn lock_screen() { fn (ved &Ved) pomodoro_minutes() int { return int((ved.now.unix - ved.timer.pom_start) / 60) } + +const ( + max_task_len = 40 + separator = '|-----------------------------------------------------------------------------|' +) + +fn (ved &Ved) insert_task() ! { + if ved.cur_task == '' || ved.task_minutes() == 0 { + return + } + start_time := time.unix(int(ved.task_start_unix)) + mut f := os.open_append(tasks_path)! + task_name := ved.cur_task.limit(max_task_len) + + strings.repeat(` `, max_task_len - ved.cur_task.len) + mins := ved.task_minutes().str() + 'm' + mins_pad := strings.repeat(` `, 4 - mins.len) + now := time.now() + if start_time.day == now.day && start_time.month == now.month { + // Single day entry + f.writeln('| ${task_name} | ${mins} ${mins_pad} | ' + start_time.format() + ' | ' + + time.now().hhmm() + ' |')! + } else { + // Two day entry (separated by 00:00) + midnight := time.Time{ + year: start_time.year + month: start_time.month + day: start_time.day + hour: 23 + minute: 59 + } + day_start := time.Time{ + year: now.year + month: now.month + day: now.day + hour: 0 + minute: 0 + } + + f.writeln('| ${task_name} | ${mins} ${mins_pad} | ' + start_time.format() + ' | ' + + midnight.hhmm() + ' |')! + f.writeln(separator)! + f.writeln('| ${task_name} | ${mins} ${mins_pad} | ' + day_start.format() + ' | ' + + time.now().hhmm() + ' |')! + } + f.writeln(separator)! + f.close() +} diff --git a/ved.v b/ved.v index 7aa12d6..abcff48 100644 --- a/ved.v +++ b/ved.v @@ -8,7 +8,6 @@ import gx import os import time import uiold -import strings import clipboard const ( @@ -1707,9 +1706,12 @@ fn (mut ved Ved) open_blog() { now := time.now() path := os.join_path(codeblog_path, '${now.year}', '${now.month:02d}', '${now.day:02d}') parent_dir := os.dir(path) + parent_dir2 := os.dir(parent_dir) + if !os.exists(parent_dir2) { + os.mkdir(parent_dir2) or { panic(err) } + } if !os.exists(parent_dir) { os.mkdir(parent_dir) or { panic(err) } - // os.system('mkdir ${parent_dir}') } if !os.exists(path) { os.system('touch ${path}') @@ -1923,53 +1925,6 @@ fn (ved &Ved) task_minutes() int { return int(seconds / 60) } -const ( - max_task_len = 40 - separator = '|-----------------------------------------------------------------------------|' -) - -fn (ved &Ved) insert_task() ! { - if ved.cur_task == '' || ved.task_minutes() == 0 { - return - } - start_time := time.unix(int(ved.task_start_unix)) - mut f := os.open_append(tasks_path)! - task_name := ved.cur_task.limit(max_task_len) + - strings.repeat(` `, max_task_len - ved.cur_task.len) - mins := ved.task_minutes().str() + 'm' - mins_pad := strings.repeat(` `, 4 - mins.len) - now := time.now() - if start_time.day == now.day && start_time.month == now.month { - // Single day entry - f.writeln('| ${task_name} | ${mins} ${mins_pad} | ' + start_time.format() + ' | ' + - time.now().hhmm() + ' |')! - } else { - // Two day entry (separated by 00:00) - midnight := time.Time{ - year: start_time.year - month: start_time.month - day: start_time.day - hour: 23 - minute: 59 - } - day_start := time.Time{ - year: now.year - month: now.month - day: now.day - hour: 0 - minute: 0 - } - - f.writeln('| ${task_name} | ${mins} ${mins_pad} | ' + start_time.format() + ' | ' + - midnight.hhmm() + ' |')! - f.writeln(separator)! - f.writeln('| ${task_name} | ${mins} ${mins_pad} | ' + day_start.format() + ' | ' + - time.now().hhmm() + ' |')! - } - f.writeln(separator)! - f.close() -} - fn (mut ved Ved) git_pull() { os.system('git -C "${ved.workspace}" pull --rebase') ved.mode = .normal