From ec4d0afefc196d4bc4a82bf68de6e28315cf1137 Mon Sep 17 00:00:00 2001 From: Sho Mizutani Date: Tue, 19 Jan 2021 11:17:02 +0900 Subject: [PATCH 1/4] Put WeekEndDate back --- README.md | 1 + src/date.go | 7 ++++++- src/date_test.go | 20 ++++++++++---------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7cebba0..4ee9b41 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ This action opens a new issue from an issue template. It parses the template's f - `.Month`: Month of the day when this action runs - `.Day`: Day when this action runs - `.WeekStartDate`: Date of Monday of the week (YYYY/MM/DD) +- `.WeekEndDate`: Date of Sunday of the week (YYYY/MM/DD) - `.WeekNumber`: ISO week number - `.WeekNumberYear`: Year of the Thursday of the week. Matches with [ISO week number](https://en.wikipedia.org/wiki/ISO_week_date#First_week) - `.Dates`: Array of the dates of the week (Can be used as `{{ index .Dates 1 }}` in the template) diff --git a/src/date.go b/src/date.go index fc12d7b..1e5c249 100644 --- a/src/date.go +++ b/src/date.go @@ -13,6 +13,7 @@ type date struct { Month string Day string WeekStartDate string + WeekEndDate string WeekNumber string WeekNumberYear string Dates [7]string @@ -29,7 +30,11 @@ func NewDate(t time.Time) *date { d.Year = strconv.Itoa(n.Year()) d.Month = fmt.Sprintf("%02d", int(n.Month())) d.Day = fmt.Sprintf("%02d", n.Day()) - d.WeekStartDate = n.BeginningOfWeek().Format("2006/01/02") + + // https://github.com/jinzhu/now#mondaysunday + d.WeekStartDate = n.Monday().Format("2006/01/02") + d.WeekEndDate = n.Sunday().Format("2006/01/02") + _, isoweek := n.Monday().ISOWeek() d.WeekNumber = fmt.Sprintf("%02d", isoweek) // Thursday of the week, should be used with the week number diff --git a/src/date_test.go b/src/date_test.go index 190bd1e..42a1850 100644 --- a/src/date_test.go +++ b/src/date_test.go @@ -14,23 +14,23 @@ type testCase struct { func TestNewDate(t *testing.T) { testCases := []testCase{ // Monday when Jan 1st is Monday - {now: "2018-01-01T00:00:00Z", should: "2018 Week 01, Week of 2018/01/01. Year 2018, Month 01, Day 01"}, + {now: "2018-01-01T00:00:00Z", should: "2018 Week 01, Week of 2018/01/01. Ends at 2018/01/07. Year 2018, Month 01, Day 01"}, // Monday when Jan 1st is Tuesday - {now: "2018-12-31T00:00:00Z", should: "2019 Week 01, Week of 2018/12/31. Year 2018, Month 12, Day 31"}, + {now: "2018-12-31T00:00:00Z", should: "2019 Week 01, Week of 2018/12/31. Ends at 2019/01/06. Year 2018, Month 12, Day 31"}, // Monday when Jan 1st is Wednesday - {now: "2019-12-30T00:00:00Z", should: "2020 Week 01, Week of 2019/12/30. Year 2019, Month 12, Day 30"}, + {now: "2019-12-30T00:00:00Z", should: "2020 Week 01, Week of 2019/12/30. Ends at 2020/01/05. Year 2019, Month 12, Day 30"}, // Monday when Jan 1st is Thursday - {now: "2025-12-29T00:00:00Z", should: "2026 Week 01, Week of 2025/12/29. Year 2025, Month 12, Day 29"}, + {now: "2025-12-29T00:00:00Z", should: "2026 Week 01, Week of 2025/12/29. Ends at 2026/01/04. Year 2025, Month 12, Day 29"}, // Monday when Jan 1st is Friday - {now: "2020-12-28T00:00:00Z", should: "2020 Week 53, Week of 2020/12/28. Year 2020, Month 12, Day 28"}, + {now: "2020-12-28T00:00:00Z", should: "2020 Week 53, Week of 2020/12/28. Ends at 2021/01/03. Year 2020, Month 12, Day 28"}, // Monday when Jan 1st is Saturday - {now: "2021-12-27T00:00:00Z", should: "2021 Week 52, Week of 2021/12/27. Year 2021, Month 12, Day 27"}, + {now: "2021-12-27T00:00:00Z", should: "2021 Week 52, Week of 2021/12/27. Ends at 2022/01/02. Year 2021, Month 12, Day 27"}, // Monday when Jan 1st is Saturday and it's a leap year - {now: "2032-12-27T00:00:00Z", should: "2032 Week 53, Week of 2032/12/27. Year 2032, Month 12, Day 27"}, + {now: "2032-12-27T00:00:00Z", should: "2032 Week 53, Week of 2032/12/27. Ends at 2033/01/02. Year 2032, Month 12, Day 27"}, // Monday when Jan 1st is Sunday - {now: "2022-12-26T00:00:00Z", should: "2022 Week 52, Week of 2022/12/26. Year 2022, Month 12, Day 26"}, + {now: "2022-12-26T00:00:00Z", should: "2022 Week 52, Week of 2022/12/26. Ends at 2023/01/01. Year 2022, Month 12, Day 26"}, // Wednesday when Jan 1st is Wednesday - {now: "2020-01-01T00:00:00Z", should: "2020 Week 01, Week of 2019/12/30. Year 2020, Month 01, Day 01"}, + {now: "2020-01-01T00:00:00Z", should: "2020 Week 01, Week of 2019/12/30. Ends at 2020/01/05. Year 2020, Month 01, Day 01"}, } for _, v := range testCases { @@ -40,7 +40,7 @@ func TestNewDate(t *testing.T) { t.Fatal(err) } d := NewDate(now) - current := fmt.Sprintf("%v Week %v, Week of %v. Year %v, Month %v, Day %v", d.WeekNumberYear, d.WeekNumber, d.WeekStartDate, d.Year, d.Month, d.Day) + current := fmt.Sprintf("%v Week %v, Week of %v. Ends at %v. Year %v, Month %v, Day %v", d.WeekNumberYear, d.WeekNumber, d.WeekStartDate, d.WeekEndDate, d.Year, d.Month, d.Day) if current != v.should { t.Fatalf("Actual: %v, Should: %v\n", current, v.should) } From a5f138854964d05aad016901ba6799ea78eb11c5 Mon Sep 17 00:00:00 2001 From: Sho Mizutani Date: Tue, 19 Jan 2021 11:35:49 +0900 Subject: [PATCH 2/4] Use shorter date format --- src/date.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/date.go b/src/date.go index 1e5c249..d5a85bc 100644 --- a/src/date.go +++ b/src/date.go @@ -32,8 +32,8 @@ func NewDate(t time.Time) *date { d.Day = fmt.Sprintf("%02d", n.Day()) // https://github.com/jinzhu/now#mondaysunday - d.WeekStartDate = n.Monday().Format("2006/01/02") - d.WeekEndDate = n.Sunday().Format("2006/01/02") + d.WeekStartDate = n.Monday().Format("01/02") + d.WeekEndDate = n.Sunday().Format("01/02") _, isoweek := n.Monday().ISOWeek() d.WeekNumber = fmt.Sprintf("%02d", isoweek) From ae921dfd0370fe38c6b1f2a3743460c779ed1075 Mon Sep 17 00:00:00 2001 From: Sho Mizutani Date: Tue, 19 Jan 2021 12:51:06 +0900 Subject: [PATCH 3/4] Update test --- src/date_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/date_test.go b/src/date_test.go index 42a1850..1f4931f 100644 --- a/src/date_test.go +++ b/src/date_test.go @@ -14,23 +14,23 @@ type testCase struct { func TestNewDate(t *testing.T) { testCases := []testCase{ // Monday when Jan 1st is Monday - {now: "2018-01-01T00:00:00Z", should: "2018 Week 01, Week of 2018/01/01. Ends at 2018/01/07. Year 2018, Month 01, Day 01"}, + {now: "2018-01-01T00:00:00Z", should: "2018 Week 01, Week of 01/01. Ends at 01/07. Year 2018, Month 01, Day 01"}, // Monday when Jan 1st is Tuesday - {now: "2018-12-31T00:00:00Z", should: "2019 Week 01, Week of 2018/12/31. Ends at 2019/01/06. Year 2018, Month 12, Day 31"}, + {now: "2018-12-31T00:00:00Z", should: "2019 Week 01, Week of 12/31. Ends at 01/06. Year 2018, Month 12, Day 31"}, // Monday when Jan 1st is Wednesday - {now: "2019-12-30T00:00:00Z", should: "2020 Week 01, Week of 2019/12/30. Ends at 2020/01/05. Year 2019, Month 12, Day 30"}, + {now: "2019-12-30T00:00:00Z", should: "2020 Week 01, Week of 12/30. Ends at 01/05. Year 2019, Month 12, Day 30"}, // Monday when Jan 1st is Thursday - {now: "2025-12-29T00:00:00Z", should: "2026 Week 01, Week of 2025/12/29. Ends at 2026/01/04. Year 2025, Month 12, Day 29"}, + {now: "2025-12-29T00:00:00Z", should: "2026 Week 01, Week of 12/29. Ends at 01/04. Year 2025, Month 12, Day 29"}, // Monday when Jan 1st is Friday - {now: "2020-12-28T00:00:00Z", should: "2020 Week 53, Week of 2020/12/28. Ends at 2021/01/03. Year 2020, Month 12, Day 28"}, + {now: "2020-12-28T00:00:00Z", should: "2020 Week 53, Week of 12/28. Ends at 01/03. Year 2020, Month 12, Day 28"}, // Monday when Jan 1st is Saturday - {now: "2021-12-27T00:00:00Z", should: "2021 Week 52, Week of 2021/12/27. Ends at 2022/01/02. Year 2021, Month 12, Day 27"}, + {now: "2021-12-27T00:00:00Z", should: "2021 Week 52, Week of 12/27. Ends at 01/02. Year 2021, Month 12, Day 27"}, // Monday when Jan 1st is Saturday and it's a leap year - {now: "2032-12-27T00:00:00Z", should: "2032 Week 53, Week of 2032/12/27. Ends at 2033/01/02. Year 2032, Month 12, Day 27"}, + {now: "2032-12-27T00:00:00Z", should: "2032 Week 53, Week of 12/27. Ends at 01/02. Year 2032, Month 12, Day 27"}, // Monday when Jan 1st is Sunday - {now: "2022-12-26T00:00:00Z", should: "2022 Week 52, Week of 2022/12/26. Ends at 2023/01/01. Year 2022, Month 12, Day 26"}, + {now: "2022-12-26T00:00:00Z", should: "2022 Week 52, Week of 12/26. Ends at 01/01. Year 2022, Month 12, Day 26"}, // Wednesday when Jan 1st is Wednesday - {now: "2020-01-01T00:00:00Z", should: "2020 Week 01, Week of 2019/12/30. Ends at 2020/01/05. Year 2020, Month 01, Day 01"}, + {now: "2020-01-01T00:00:00Z", should: "2020 Week 01, Week of 12/30. Ends at 01/05. Year 2020, Month 01, Day 01"}, } for _, v := range testCases { From 50ec1c0753725a7bdc17acf0d4ffd9df309208e7 Mon Sep 17 00:00:00 2001 From: Sho Mizutani Date: Tue, 19 Jan 2021 12:52:32 +0900 Subject: [PATCH 4/4] Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4ee9b41..b0afd90 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ This action opens a new issue from an issue template. It parses the template's f - `.Year`: Year of the day when this action runs - `.Month`: Month of the day when this action runs - `.Day`: Day when this action runs -- `.WeekStartDate`: Date of Monday of the week (YYYY/MM/DD) -- `.WeekEndDate`: Date of Sunday of the week (YYYY/MM/DD) +- `.WeekStartDate`: Date of Monday of the week (MM/DD) +- `.WeekEndDate`: Date of Sunday of the week (MM/DD) - `.WeekNumber`: ISO week number - `.WeekNumberYear`: Year of the Thursday of the week. Matches with [ISO week number](https://en.wikipedia.org/wiki/ISO_week_date#First_week) - `.Dates`: Array of the dates of the week (Can be used as `{{ index .Dates 1 }}` in the template)