第一次改用 go 改模板,代码比较乱,才接触 go 语言不久,应该还有更加简单的方式,大佬们可以在评论里指点一下
发现问题点
发现日期无法根据时间更新。
根据 Normal 模板,魔改了
-
自动识别
距离明年1月1日的时间
,使其可以随时间变换 -
自动识别更新本年周数
具体修改如下
日计划添加代码
.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 " ")}
周计划添加代码
.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 " ")}
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于