Skip to content

Commit

Permalink
heat estimation change request supports time zone changes
Browse files Browse the repository at this point in the history
  • Loading branch information
konrad2002 committed Oct 24, 2024
1 parent 0aa2065 commit af1bba4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion controller/heat_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func updateHeatsStartEstimationDate(c *gin.Context) {
return
}

info, err := service.UpdateHeatsEstimationDateByMeetingAndEvent(meeting, event, request.Time)
info, err := service.UpdateHeatsEstimationDateByMeetingAndEvent(meeting, event, request.Time, request.UpdateTimeZone)
if err != nil {
c.IndentedJSON(http.StatusNotFound, gin.H{"message": err.Error()})
return
Expand Down
3 changes: 2 additions & 1 deletion dto/heat_estimation_date_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package dto
import "time"

type HeatEstimationDateRequest struct {
Time time.Time `json:"time"`
Time time.Time `json:"time"`
UpdateTimeZone bool `json:"update_time_zone"`
}
11 changes: 9 additions & 2 deletions service/heat_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func UpdateHeatTimes(id primitive.ObjectID, time time.Time, timeType string) (mo
return UpdateHeat(heat)
}

func UpdateHeatsEstimationDateByMeetingAndEvent(meeting string, event int, t time.Time) ([]model.Heat, error) {
func UpdateHeatsEstimationDateByMeetingAndEvent(meeting string, event int, t time.Time, updateTimeZone bool) ([]model.Heat, error) {
heats, err := GetHeatsByMeetingAndEvent(meeting, event)
if err != nil {
return []model.Heat{}, err
Expand All @@ -461,7 +461,14 @@ func UpdateHeatsEstimationDateByMeetingAndEvent(meeting string, event int, t tim
for _, heat := range heats {
t2 := heat.StartEstimation

heat.StartEstimation = time.Date(t.Year(), t.Month(), t.Day(), t2.Hour(), t2.Minute(), t2.Second(), t2.Nanosecond(), t2.Location())
var timezone *time.Location
if updateTimeZone {
timezone = t.Location()
} else {
timezone = t2.Location()
}

heat.StartEstimation = time.Date(t.Year(), t.Month(), t.Day(), t2.Hour(), t2.Minute(), t2.Second(), t2.Nanosecond(), timezone)

saved, err := UpdateHeat(heat)
if err != nil {
Expand Down

0 comments on commit af1bba4

Please sign in to comment.