mirror of
https://github.com/muhac/chinese-holidays-calendar.git
synced 2025-02-17 17:59:48 +08:00
Merge pull request #18 from theRank/patch-december
This commit is contained in:
commit
30bc2ad8c7
15
.editorconfig
Executable file
15
.editorconfig
Executable file
@ -0,0 +1,15 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
# Matches multiple files with brace expansion notation
|
||||
[*.{py,java,cpp,go,js,html}]
|
||||
charset = utf-8
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
@ -2,7 +2,7 @@
|
||||
|
||||
subscription link of public holidays in mainland China
|
||||
|
||||
> Calendar data updated at: March 27, 2022
|
||||
> Calendar data updated at 23:21 on March 27, 2022
|
||||
|
||||
## Demo
|
||||
|
||||
|
@ -25,15 +25,15 @@ def main():
|
||||
with open(file, 'w') as f:
|
||||
f.write(
|
||||
f"{comments[0]} ({beijing_time().strftime('%-m/%-d/%Y')})\n"
|
||||
f"{comments[1]}\n\n// source: {link}\n\n{holidays}"
|
||||
f"{comments[1]}\n// source: {link}\n\n{holidays}"
|
||||
)
|
||||
|
||||
update_info = "> Calendar data updated at: "
|
||||
update_info = "> Calendar data updated "
|
||||
with open('./README.md', 'r') as f:
|
||||
content = f.read().split('\n')
|
||||
for i in range(len(content)):
|
||||
if content[i].startswith(update_info):
|
||||
content[i] = update_info + beijing_time().strftime("%B %-d, %Y")
|
||||
content[i] = update_info + beijing_time().strftime("at %-H:%M on %B %-d, %Y")
|
||||
with open('./README.md', 'w') as f:
|
||||
f.write('\n'.join(content))
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
// automatically generated by crawler.py (3/27/2022)
|
||||
// manually checked by DATA NOT VERIFIED
|
||||
|
||||
// source: http://www.gov.cn/zhengce/content/2012-12/10/content_1353.htm
|
||||
|
||||
元旦;1.1-1.3;1.5,1.6 // 1月1日至3日放假调休,共3天。1月5日(星期六)、1月6日(星期日)上班。
|
||||
|
@ -1,6 +1,5 @@
|
||||
// automatically generated by crawler.py (3/27/2022)
|
||||
// manually checked by DATA NOT VERIFIED
|
||||
|
||||
// source: http://www.gov.cn/zhengce/content/2014-01/02/content_1194.htm
|
||||
|
||||
元旦;1.1; // 1月1日放假1天。
|
||||
|
@ -1,6 +1,5 @@
|
||||
// automatically generated by crawler.py (3/27/2022)
|
||||
// manually checked by DATA NOT VERIFIED
|
||||
|
||||
// source: http://www.gov.cn/zhengce/content/2014-12/16/content_9302.htm
|
||||
|
||||
元旦;1.1-1.3;1.4 // 1月1日至3日放假调休,共3天。1月4日(星期日)上班。
|
||||
|
@ -1,6 +1,5 @@
|
||||
// automatically generated by crawler.py (3/27/2022)
|
||||
// manually checked by DATA NOT VERIFIED
|
||||
|
||||
// source: http://www.gov.cn/zhengce/content/2015-12/10/content_10394.htm
|
||||
|
||||
元旦;1.1; // 1月1日放假,与周末连休。
|
||||
|
@ -1,6 +1,5 @@
|
||||
// automatically generated by crawler.py (3/27/2022)
|
||||
// manually checked by DATA NOT VERIFIED
|
||||
|
||||
// source: http://www.gov.cn/zhengce/content/2016-12/01/content_5141603.htm
|
||||
|
||||
元旦;1.1; // 1月1日放假,1月2日(星期一)补休。
|
||||
|
@ -1,12 +1,11 @@
|
||||
// automatically generated by crawler.py (3/27/2022)
|
||||
// manually checked by DATA NOT VERIFIED
|
||||
|
||||
// manually checked by @bugstop (3/27/2022)
|
||||
// source: http://www.gov.cn/zhengce/content/2017-11/30/content_5243579.htm
|
||||
|
||||
元旦;1.1; // 1月1日放假,与周末连休。
|
||||
元旦;0.2-1.1; // 1月1日放假,与周末连休。
|
||||
春节;2.15-2.21;2.11,2.24 // 2月15日至21日放假调休,共7天。2月11日(星期日)、2月24日(星期六)上班。
|
||||
清明节;4.5-4.7;4.8 // 4月5日至7日放假调休,共3天。4月8日(星期日)上班。
|
||||
劳动节;4.29-5.1;4.28 // 4月29日至5月1日放假调休,共3天。4月28日(星期六)上班。
|
||||
端午节;6.18; // 6月18日放假,与周末连休。
|
||||
中秋节;9.24; // 9月24日放假,与周末连休。
|
||||
端午节;6.16-6.18; // 6月18日放假,与周末连休。
|
||||
中秋节;9.22-9.24; // 9月24日放假,与周末连休。
|
||||
国庆节;10.1-10.7;9.29,9.30 // 10月1日至7日放假调休,共7天。9月29日(星期六)、9月30日(星期日)上班。
|
@ -1,12 +1,11 @@
|
||||
// automatically generated by crawler.py (3/27/2022)
|
||||
// manually checked by DATA NOT VERIFIED
|
||||
|
||||
// manually checked by @bugstop (3/27/2022)
|
||||
// source: http://www.gov.cn/zhengce/content/2018-12/06/content_5346276.htm
|
||||
|
||||
元旦;12.30;12.29 // 2018年12月30日至2019年1月1日放假调休,共3天。2018年12月29日(星期六)上班。
|
||||
元旦;0.2-1.1;0.3 // 2018年12月30日至2019年1月1日放假调休,共3天。2018年12月29日(星期六)上班。
|
||||
春节;2.4-2.10;2.2,2.3 // 2月4日至10日放假调休,共7天。2月2日(星期六)、2月3日(星期日)上班。
|
||||
清明节;4.5; // 4月5日放假,与周末连休。
|
||||
清明节;4.5-4.7; // 4月5日放假,与周末连休。
|
||||
劳动节;5.1; // 5月1日放假。
|
||||
端午节;6.7; // 6月7日放假,与周末连休。
|
||||
中秋节;9.13; // 9月13日放假,与周末连休。
|
||||
端午节;6.7-6.9; // 6月7日放假,与周末连休。
|
||||
中秋节;9.13-9.15; // 9月13日放假,与周末连休。
|
||||
国庆节;10.1-10.7;9.29,10.12 // 10月1日至7日放假调休,共7天。9月29日(星期日)、10月12日(星期六)上班。
|
@ -1,6 +1,5 @@
|
||||
// automatically generated by crawler.py (3/27/2022)
|
||||
// manually checked by DATA NOT VERIFIED
|
||||
|
||||
// manually checked by @bugstop (3/27/2022)
|
||||
// source: http://www.gov.cn/zhengce/content/2019-11/21/content_5454164.htm
|
||||
|
||||
元旦;1.1; // 2020年1月1日放假,共1天。
|
||||
|
@ -1,6 +1,5 @@
|
||||
// automatically generated by crawler.py (3/27/2022)
|
||||
// manually checked by @bugstop (3/27/2022)
|
||||
|
||||
// source: http://www.gov.cn/zhengce/content/2020-11/25/content_5564127.htm
|
||||
|
||||
元旦;1.1-1.3; // 2021年1月1日至3日放假,共3天。
|
||||
|
@ -1,6 +1,5 @@
|
||||
// automatically generated by crawler.py (3/27/2022)
|
||||
// manually checked by @bugstop (3/27/2022)
|
||||
|
||||
// source: http://www.gov.cn/zhengce/content/2021-10/25/content_5644835.htm
|
||||
|
||||
元旦;1.1-1.3; // 2022年1月1日至3日放假,共3天。
|
||||
|
458
docs/holiday.ics
458
docs/holiday.ics
File diff suppressed because it is too large
Load Diff
458
docs/index.html
458
docs/index.html
File diff suppressed because it is too large
Load Diff
382
docs/rest.ics
382
docs/rest.ics
File diff suppressed because it is too large
Load Diff
@ -272,39 +272,39 @@ END:VEVENT
|
||||
|
||||
BEGIN:VEVENT
|
||||
UID:ac7fa11a-6372-48b1-a0a8-c9ad837a26d0
|
||||
DTSTART;VALUE=DATE:20181229
|
||||
SUMMARY:元旦补班
|
||||
DESCRIPTION:补班 第1天/共1天
|
||||
END:VEVENT
|
||||
|
||||
BEGIN:VEVENT
|
||||
UID:408c0fce-7bf0-4a4c-ba71-5f74d4490065
|
||||
DTSTART;VALUE=DATE:20190202
|
||||
SUMMARY:春节补班
|
||||
DESCRIPTION:补班 第1天/共2天
|
||||
END:VEVENT
|
||||
|
||||
BEGIN:VEVENT
|
||||
UID:408c0fce-7bf0-4a4c-ba71-5f74d4490065
|
||||
UID:a20e3946-33b6-4fe1-b4c6-e348cd9e88c0
|
||||
DTSTART;VALUE=DATE:20190203
|
||||
SUMMARY:春节补班
|
||||
DESCRIPTION:补班 第2天/共2天
|
||||
END:VEVENT
|
||||
|
||||
BEGIN:VEVENT
|
||||
UID:a20e3946-33b6-4fe1-b4c6-e348cd9e88c0
|
||||
UID:02d4ef2d-549e-4d06-ab4f-e6baaafdd9f9
|
||||
DTSTART;VALUE=DATE:20190929
|
||||
SUMMARY:国庆节补班
|
||||
DESCRIPTION:补班 第1天/共2天
|
||||
END:VEVENT
|
||||
|
||||
BEGIN:VEVENT
|
||||
UID:02d4ef2d-549e-4d06-ab4f-e6baaafdd9f9
|
||||
UID:6fdd77e5-1b99-4044-86cb-f8a656aa81b2
|
||||
DTSTART;VALUE=DATE:20191012
|
||||
SUMMARY:国庆节补班
|
||||
DESCRIPTION:补班 第2天/共2天
|
||||
END:VEVENT
|
||||
|
||||
BEGIN:VEVENT
|
||||
UID:6fdd77e5-1b99-4044-86cb-f8a656aa81b2
|
||||
DTSTART;VALUE=DATE:20191229
|
||||
SUMMARY:元旦补班
|
||||
DESCRIPTION:补班 第1天/共1天
|
||||
END:VEVENT
|
||||
|
||||
BEGIN:VEVENT
|
||||
UID:1bc6650f-97ca-4fad-bde7-ff4fdb32cf4c
|
||||
DTSTART;VALUE=DATE:20200119
|
||||
|
@ -4,7 +4,3 @@ const (
|
||||
Rest = iota // 假日
|
||||
Work // 补班
|
||||
)
|
||||
|
||||
const (
|
||||
ICS = "ics" // .ics 文件
|
||||
)
|
||||
|
@ -1,13 +1,14 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"main/parse/base"
|
||||
"main/parse/data"
|
||||
"main/parse/data/input"
|
||||
"main/parse/data/output"
|
||||
"main/parse/data/read"
|
||||
"main/parse/data/write"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func newHandler(optional ...base.Holidays) Handler {
|
||||
|
@ -2,9 +2,10 @@ package input
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"main/parse/base"
|
||||
"main/parse/data"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func NewParser() data.Parser {
|
||||
@ -34,7 +35,7 @@ func parse(raw data.InputRaw) (result base.Holidays, err error) {
|
||||
Group: groupName,
|
||||
Name: info[0],
|
||||
Nth: i + 1,
|
||||
Date: date(raw.Year, day),
|
||||
Date: day,
|
||||
Type: base.Rest,
|
||||
}
|
||||
result = append(result, restDay)
|
||||
@ -46,7 +47,7 @@ func parse(raw data.InputRaw) (result base.Holidays, err error) {
|
||||
Group: groupName,
|
||||
Name: info[0],
|
||||
Nth: i + 1,
|
||||
Date: date(raw.Year, day),
|
||||
Date: day,
|
||||
Type: base.Work,
|
||||
}
|
||||
result = append(result, workDay)
|
||||
|
@ -2,6 +2,7 @@ package input
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@ -9,10 +10,15 @@ import (
|
||||
func date(year int, date string) (result time.Time) {
|
||||
input := fmt.Sprintf("%04d-%s", year, date)
|
||||
result, _ = time.Parse("2006-1.2", input)
|
||||
|
||||
if date[0] == '0' { // => 0001-1.1
|
||||
delta, _ := strconv.Atoi(date[2:]) // days before
|
||||
result = result.AddDate(year-1, 0, -delta)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func holidays(year int, daysRaw string) (result []string) {
|
||||
func holidays(year int, daysRaw string) (result []time.Time) {
|
||||
if daysRaw == "" {
|
||||
return
|
||||
}
|
||||
@ -22,10 +28,10 @@ func holidays(year int, daysRaw string) (result []string) {
|
||||
if strings.Contains(day, "-") {
|
||||
period := strings.Split(day, "-")
|
||||
for d := date(year, period[0]); !d.After(date(year, period[1])); d = d.AddDate(0, 0, 1) {
|
||||
result = append(result, d.Format("1.2"))
|
||||
result = append(result, d)
|
||||
}
|
||||
} else {
|
||||
result = append(result, day)
|
||||
result = append(result, date(year, day))
|
||||
}
|
||||
}
|
||||
return result
|
||||
|
@ -21,6 +21,7 @@ func Test_date(t *testing.T) {
|
||||
{"3", args{2003, "11.1"}, time.Date(2003, 11, 1, 0, 0, 0, 0, time.UTC)},
|
||||
{"4", args{2004, "11.11"}, time.Date(2004, 11, 11, 0, 0, 0, 0, time.UTC)},
|
||||
{"5", args{2005, "1.41"}, time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||
{"6", args{2006, "0.1"}, time.Date(2005, 12, 31, 0, 0, 0, 0, time.UTC)},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@ -41,16 +42,22 @@ func Test_holidays(t *testing.T) {
|
||||
args args
|
||||
wantResult []string
|
||||
}{
|
||||
{"1", args{1, "1.1"}, []string{"1.1"}},
|
||||
{"2", args{1, "1.1,2.2"}, []string{"1.1", "2.2"}},
|
||||
{"3", args{1, "1.1-1.3"}, []string{"1.1", "1.2", "1.3"}},
|
||||
{"4", args{1, "1.1-1.3,2.2,3.3-3.4"}, []string{"1.1", "1.2", "1.3", "2.2", "3.3", "3.4"}},
|
||||
{"5", args{1, "1.31-2.2"}, []string{"1.31", "2.1", "2.2"}},
|
||||
{"1", args{1, "1.1"}, []string{"01.1.1"}},
|
||||
{"2", args{1, "1.1,2.2"}, []string{"01.1.1", "01.2.2"}},
|
||||
{"3", args{1, "1.1-1.3"}, []string{"01.1.1", "01.1.2", "01.1.3"}},
|
||||
{"4", args{1, "1.1-1.3,2.2,3.3-3.4"}, []string{"01.1.1", "01.1.2", "01.1.3", "01.2.2", "01.3.3", "01.3.4"}},
|
||||
{"5", args{1, "1.31-2.2"}, []string{"01.1.31", "01.2.1", "01.2.2"}},
|
||||
{"6", args{1, "0.2"}, []string{"00.12.30"}},
|
||||
{"7", args{1, "0.4-0.1"}, []string{"00.12.28", "00.12.29", "00.12.30", "00.12.31"}},
|
||||
{"8", args{1, "0.2-1.2"}, []string{"00.12.30", "00.12.31", "01.1.1", "01.1.2"}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotResult := holidays(tt.args.year, tt.args.daysRaw); !reflect.DeepEqual(gotResult, tt.wantResult) {
|
||||
t.Errorf("holidays() = %v, want %v", gotResult, tt.wantResult)
|
||||
gotResult := holidays(tt.args.year, tt.args.daysRaw)
|
||||
for idx, result := range gotResult{
|
||||
if !reflect.DeepEqual(result.Format("06.1.2"), tt.wantResult[idx]) {
|
||||
t.Errorf("holidays() = %v, want %v", result, tt.wantResult[idx])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"main/parse/base"
|
||||
)
|
||||
import "main/parse/base"
|
||||
|
||||
type Reader interface {
|
||||
Read() Input
|
||||
|
@ -2,11 +2,13 @@ package output
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"hash/crc32"
|
||||
"math/rand"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"main/parse/base"
|
||||
"main/parse/data"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
func NewFormatter(name string) data.Formatter {
|
||||
|
@ -2,8 +2,9 @@ package output
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"main/parse/base"
|
||||
"time"
|
||||
|
||||
"main/parse/base"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -4,11 +4,12 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"main/parse/data"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"main/parse/data"
|
||||
)
|
||||
|
||||
func NewReader(dir, file string) data.Reader {
|
||||
|
@ -3,9 +3,10 @@ package write
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"main/parse/data"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"main/parse/data"
|
||||
)
|
||||
|
||||
func NewWriter(dir, file string) data.Writer {
|
||||
|
Loading…
Reference in New Issue
Block a user