添加 Normal 模板自动识别距离明年的时间

本贴最后更新于 566 天前,其中的信息可能已经时过境迁

第一次改用 go 改模板,代码比较乱,才接触 go 语言不久,应该还有更加简单的方式,大佬们可以在评论里指点一下

发现问题点

发现日期无法根据时间更新。

根据 Normal 模板,魔改了

  1. 自动识别 距离明年1月1日的时间,使其可以随时间变换

    image.png

  2. 自动识别更新本年周数

    image.png

具体修改如下

日计划添加代码

image.png


.action{/*
newyearfirstday    		明年第一天
yearfirstday			今年第一天
yearfirstdayweek		今年第一天星期几
data_26 ~ data_31		中间变量 推断本年第一周的星期天是几号
yearfirstdayweeksunday	值 推断本年第一周的星期天是几号
*/}

.action{$newyearfirstday := (cat ((add (now | date "2006") 1) ) "01 01") | replace " " "-"}
.action{$yearfirstday := (cat (now | date "2006") "01 01") | replace " " "-"}
.action{$yearfirstdayweek := add (mod (div ((toDate "2006-01-02" "2050-03-13").Sub (toDate "2006-01-02" $yearfirstday)).Hours 24) 7) 1}
.action{$dayleft := (div ((toDate "2006-01-02" $newyearfirstday).Sub now).Hours 24)}
.action{$week := add (mod (div ((toDate "2006-01-02" "2050-03-13").Sub now).Hours 24) 7) 1}


.action{$data_26 := (cat ((sub (now | date "2006") 1) ) "12 26") | replace " " "-"}
.action{$data_27 := (cat ((sub (now | date "2006") 1) ) "12 27") | replace " " "-"}
.action{$data_28 := (cat ((sub (now | date "2006") 1) ) "12 28") | replace " " "-"}
.action{$data_29 := (cat ((sub (now | date "2006") 1) ) "12 29") | replace " " "-"}
.action{$data_30 := (cat ((sub (now | date "2006") 1) ) "12 30") | replace " " "-"}
.action{$data_31 := (cat ((sub (now | date "2006") 1) ) "12 31") | replace " " "-"}

.action{$yearfirstdayweeksunday := (last (slice (list $yearfirstday $data_26 $data_27 $data_28 $data_29 $data_30 $data_31) 0 $yearfirstdayweek ))}



.action{/*获取当前是第几周*/}
	.action{$ng_duration := (toDate "2006-01-02" $yearfirstdayweeksunday).Sub now}
	.action{$weekhours:=mul 7 24}
	.action{$duration:=sub 0 $ng_duration.Hours }
	.action{$weeks := add (div (div (now.Sub (toDate "2006-01-02" $yearfirstdayweeksunday)).Hours 24) 7) 1}
	.action{$today:= (now | date "2006-01")}
	.action{$weekResult:= (list $today "Week" $weeks| join " ")}

周计划添加代码

image.png

.action{/*
newyearfirstday    		明年第一天
yearfirstday			今年第一天
yearfirstdayweek		今年第一天星期几
data_26 ~ data_31		中间变量 推断本年第一周的星期天是几号
yearfirstdayweeksunday	值 推断本年第一周的星期天是几号
*/}

.action{$newyearfirstday := (cat ((add (now | date "2006") 1) ) "01 01") | replace " " "-"}
.action{$yearfirstday := (cat (now | date "2006") "01 01") | replace " " "-"}
.action{$yearfirstdayweek := add (mod (div ((toDate "2006-01-02" "2050-03-13").Sub (toDate "2006-01-02" $yearfirstday)).Hours 24) 7) 1}
.action{$dayleft := (div ((toDate "2006-01-02" $newyearfirstday).Sub now).Hours 24)}
.action{$week := add (mod (div ((toDate "2006-01-02" "2050-03-13").Sub now).Hours 24) 7) 1}


.action{$data_26 := (cat ((sub (now | date "2006") 1) ) "12 26") | replace " " "-"}
.action{$data_27 := (cat ((sub (now | date "2006") 1) ) "12 27") | replace " " "-"}
.action{$data_28 := (cat ((sub (now | date "2006") 1) ) "12 28") | replace " " "-"}
.action{$data_29 := (cat ((sub (now | date "2006") 1) ) "12 29") | replace " " "-"}
.action{$data_30 := (cat ((sub (now | date "2006") 1) ) "12 30") | replace " " "-"}
.action{$data_31 := (cat ((sub (now | date "2006") 1) ) "12 31") | replace " " "-"}

.action{$yearfirstdayweeksunday := (last (slice (list $yearfirstday $data_26 $data_27 $data_28 $data_29 $data_30 $data_31) 0 $yearfirstdayweek ))}


.action{$ng_duration := (toDate "2006-01-02" $yearfirstdayweeksunday).Sub now}
.action{$weekhours:=mul 7 24}
.action{$duration:=sub 0 $ng_duration.Hours }
.action{$week := add (div (div (now.Sub (toDate "2006-01-02" $yearfirstdayweeksunday)).Hours 24) 7) 1}
.action{$today:= (now | date "2006-01")}
.action{$weekResult:= (list $today "Week" $week| join " ")}
  • 思源笔记

    思源笔记是一款隐私优先的个人知识管理系统,支持完全离线使用,同时也支持端到端加密同步。

    融合块、大纲和双向链接,重构你的思维。

    23019 引用 • 92593 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...