-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ add FilterDuration and replace FilterTime in InitPostEvent… #544
Changes from 1 commit
8280e0a
a2b852e
68fa95b
e80bc38
0b24a6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,3 +93,85 @@ func AddAnd(lhs, rhs Expr) Expr { | |
Rhs: rhs, | ||
} | ||
} | ||
|
||
func addOr(lhs, rhs Expr) Expr { | ||
if lhs == nil && rhs == nil { | ||
return nil | ||
} | ||
if lhs == nil { | ||
return rhs | ||
} | ||
if rhs == nil { | ||
return lhs | ||
} | ||
return &LogicOpExpr{ | ||
LogicOp: Or, | ||
Lhs: lhs, | ||
Rhs: rhs, | ||
} | ||
} | ||
|
||
// 期間中に始まる | ||
// time_start >= min AND time_start < max | ||
// | ||
// 期間中に終わる | ||
// time_end >= min AND time_end < max | ||
// | ||
// 期間より前に始まり期間より後に終わる | ||
// time_start < min AND time_end >= max | ||
// | ||
// min < max であるべき | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. これは直接コードで |
||
func FilterDuration(min, max time.Time) Expr { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 最近minとmaxがbuiltinの関数名に追加されたので他の名前にしておくと余計な誤解を招かなくてよいです(動きはするんですが) since, untilなど |
||
startAfterMin := &CmpExpr{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここもstartAfterSinceとかにしたいが流石に文法に違和感があるのであまりいい名前が思いつかない |
||
Attr: AttrTimeStart, | ||
Relation: GreterEq, | ||
Value: min, | ||
} | ||
startBeforeMax := &CmpExpr{ | ||
Attr: AttrTimeStart, | ||
Relation: Less, | ||
Value: max, | ||
} | ||
// 期間中に始まる | ||
startIn := &LogicOpExpr{ | ||
LogicOp: And, | ||
Lhs: startAfterMin, | ||
Rhs: startBeforeMax, | ||
} | ||
|
||
endAfterMin := &CmpExpr{ | ||
Attr: AttrTimeEnd, | ||
Relation: GreterEq, | ||
Value: min, | ||
} | ||
endBeforeMax := &CmpExpr{ | ||
Attr: AttrTimeEnd, | ||
Relation: Less, | ||
Value: max, | ||
} | ||
// 期間中に終わる | ||
endIn := &LogicOpExpr{ | ||
LogicOp: And, | ||
Lhs: endAfterMin, | ||
Rhs: endBeforeMax, | ||
} | ||
|
||
startBeforeMin := &CmpExpr{ | ||
Attr: AttrTimeStart, | ||
Relation: Less, | ||
Value: min, | ||
} | ||
endAfterMax := &CmpExpr{ | ||
Attr: AttrTimeEnd, | ||
Relation: GreterEq, | ||
Value: max, | ||
} | ||
// 期間より前に始まり期間より後に終わる | ||
throughout := &LogicOpExpr{ | ||
LogicOp: And, | ||
Lhs: startBeforeMin, | ||
Rhs: endAfterMax, | ||
} | ||
|
||
return addOr(addOr(startIn, endIn), throughout) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addOr使わずに直接書いた方が見やすそう(この関数内のAndはそうしてるし) |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ func InitPostEventToTraQ(repo *db.GormRepository, secret, channelID, webhookID, | |
tomorrow := now.AddDate(0, 0, 1) | ||
|
||
rooms, _ := repo.GetAllRooms(now, tomorrow, uuid.Nil) | ||
events, _ := repo.GetAllEvents(filter.FilterTime(now, tomorrow)) | ||
events, _ := repo.GetAllEvents(filter.FilterDuration(now, tomorrow)) | ||
message := createMessage(now, rooms, events, origin) | ||
err := RequestWebhook(message, secret, channelID, webhookID, 1) | ||
if err != nil { | ||
|
@@ -162,8 +162,8 @@ func createMessage(t time.Time, rooms []*domain.Room, events []*db.Event, origin | |
|
||
} else { | ||
for _, event := range events { | ||
eventMessage += fmt.Sprintf("- [%s](%s/events/%s) %s ~ %s @%s %s\n", event.Name, origin, event.ID, | ||
event.TimeStart.In(tz.JST).Format("15:04"), event.TimeEnd.In(tz.JST).Format("15:04"), | ||
eventMessage += fmt.Sprintf("- [%s](%s/events/%s) %s:%s ~ %s:%s @%s %s\n", event.Name, origin, event.ID, | ||
event.TimeStart.In(tz.JST).Format("01/02"), event.TimeStart.In(tz.JST).Format("15:04"), event.TimeEnd.In(tz.JST).Format("01/02"), event.TimeEnd.In(tz.JST).Format("15:04"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
event.Room.Place, combined[event.AllowTogether]) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これをORで繋ぐことを明記すると良いと思います