enhance(types):日期区间范围增加常用方法的易用性。

This commit is contained in:
徐涛 2023-06-16 08:40:15 +08:00
parent b244fd5823
commit fb388c53c7
2 changed files with 12 additions and 8 deletions

View File

@ -91,9 +91,10 @@ func (dr *DateRange) UnmarshalJSON(data []byte) error {
return nil
}
func (dr *DateRange) SetLower(lower Date, bound pgtype.BoundType) {
func (dr *DateRange) SetLower(lower Date, bound ...pgtype.BoundType) {
bound = append(bound, pgtype.Inclusive)
dr.Range.Lower = lower
dr.Range.LowerType = bound
dr.Range.LowerType = bound[0]
}
func (dr *DateRange) SetLowerUnbounded() {
@ -101,9 +102,10 @@ func (dr *DateRange) SetLowerUnbounded() {
dr.Range.LowerType = pgtype.Unbounded
}
func (dr *DateRange) SetUpper(upper Date, bound pgtype.BoundType) {
func (dr *DateRange) SetUpper(upper Date, bound ...pgtype.BoundType) {
bound = append(bound, pgtype.Inclusive)
dr.Range.Upper = upper
dr.Range.UpperType = bound
dr.Range.UpperType = bound[0]
}
func (dr *DateRange) SetUpperUnbounded() {

View File

@ -91,9 +91,10 @@ func (dr *DateTimeRange) UnmarshalJSON(data []byte) error {
return nil
}
func (dr *DateTimeRange) SetLower(lower DateTime, bound pgtype.BoundType) {
func (dr *DateTimeRange) SetLower(lower DateTime, bound ...pgtype.BoundType) {
bound = append(bound, pgtype.Inclusive)
dr.Range.Lower = lower
dr.Range.LowerType = bound
dr.Range.LowerType = bound[0]
}
func (dr *DateTimeRange) SetLowerUnbounded() {
@ -101,9 +102,10 @@ func (dr *DateTimeRange) SetLowerUnbounded() {
dr.Range.LowerType = pgtype.Unbounded
}
func (dr *DateTimeRange) SetUpper(upper DateTime, bound pgtype.BoundType) {
func (dr *DateTimeRange) SetUpper(upper DateTime, bound ...pgtype.BoundType) {
bound = append(bound, pgtype.Inclusive)
dr.Range.Upper = upper
dr.Range.UpperType = bound
dr.Range.UpperType = bound[0]
}
func (dr *DateTimeRange) SetUpperUnbounded() {