You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by "abeizn (via GitHub)" <gi...@apache.org> on 2023/05/12 04:05:10 UTC

[GitHub] [incubator-devlake] abeizn opened a new pull request, #5168: feat: provide a calendar_months table

abeizn opened a new pull request, #5168:
URL: https://github.com/apache/incubator-devlake/pull/5168

   ### Summary
   migration: provide a calendar_months table
   
   ### Does this close any open issues?
   part of #4747 
   
   ### Screenshots
   ![image](https://github.com/apache/incubator-devlake/assets/101256042/2df740f4-29f8-47e8-ab4b-34c1c2ae811f)
   
   
   ### Other Information
   Any other information that is important to this PR.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] mindlesscloud merged pull request #5168: feat: provide a calendar_months table

Posted by "mindlesscloud (via GitHub)" <gi...@apache.org>.
mindlesscloud merged PR #5168:
URL: https://github.com/apache/incubator-devlake/pull/5168


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] mindlesscloud commented on a diff in pull request #5168: feat: provide a calendar_months table

Posted by "mindlesscloud (via GitHub)" <gi...@apache.org>.
mindlesscloud commented on code in PR #5168:
URL: https://github.com/apache/incubator-devlake/pull/5168#discussion_r1191975312


##########
backend/core/models/migrationscripts/20230511_add_calendar_months.go:
##########
@@ -0,0 +1,69 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package migrationscripts
+
+import (
+	"time"
+
+	"github.com/apache/incubator-devlake/core/context"
+	"github.com/apache/incubator-devlake/core/errors"
+	"github.com/apache/incubator-devlake/helpers/migrationhelper"
+)
+
+type addCalendarMonths struct{}
+
+type calendarMonths struct {
+	Month          string    `gorm:"primaryKey;type:varchar(20)"`
+	MonthTimestamp time.Time `gorm:"type:timestamp"`
+}
+
+func (calendarMonths) TableName() string {
+	return "calendar_months"
+}
+
+func (u *addCalendarMonths) Up(baseRes context.BasicRes) errors.Error {
+	db := baseRes.GetDal()
+	err := migrationhelper.AutoMigrateTables(
+		baseRes,
+		&calendarMonths{},
+	)
+	if err != nil {
+		return err
+	}
+	now := time.Now()
+	startDate := now.AddDate(-2, 0, 0)
+	endDate := now.AddDate(10, 0, 0)
+
+	var months []calendarMonths
+	for d := endDate; d.After(startDate); d = d.AddDate(0, -1, 0) {

Review Comment:
   > AddDate normalizes its result in the same way that Date does,
    so, for example, adding one month to October 31 yields
   December 1, the normalized form for November 31.
   
   According to the Doc of `Time.AddDate`, `d.AddDate(0, -1, 0)` doesn't look like what we want



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org