github.com/aacfactory/fns@v1.2.85/commons/times/range.go (about)

     1  /*
     2   * Copyright 2023 Wang Min Xiang
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   * 	http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   *
    16   */
    17  
    18  package times
    19  
    20  import (
    21  	"github.com/aacfactory/json"
    22  	"time"
    23  )
    24  
    25  func NewTimeRange(left time.Time, right time.Time) (v *TimeRange) {
    26  	v = &TimeRange{
    27  		Beg: left,
    28  		End: right,
    29  	}
    30  	return
    31  }
    32  
    33  // TimeRange
    34  // @title TimeRange
    35  // @description `['2006-01-01T15:04:06Z', '2006-01-01T15:04:06Z')`
    36  type TimeRange struct {
    37  	// Beg
    38  	// @title Beg
    39  	// @description `2006-01-01T15:04:06Z`
    40  	Beg time.Time `json:"beg"`
    41  	// End
    42  	// @title End
    43  	// @description `2006-01-01T15:04:06Z`
    44  	End time.Time `json:"end"`
    45  }
    46  
    47  func (tr *TimeRange) IsZero() (ok bool) {
    48  	ok = tr.Beg.IsZero() && tr.End.IsZero()
    49  	return
    50  }
    51  
    52  func NewDateRange(left json.Date, right json.Date) (v *DateRange) {
    53  	v = &DateRange{
    54  		Beg: left,
    55  		End: right,
    56  	}
    57  	return
    58  }
    59  
    60  // DateRange
    61  // @title DateRange
    62  // @description `['2006-01-01', '2006-01-01')`
    63  type DateRange struct {
    64  	// Beg
    65  	// @title Beg
    66  	// @description `2006-01-01`
    67  	Beg json.Date `json:"beg"`
    68  	// End
    69  	// @title End
    70  	// @description `2006-01-01`
    71  	End json.Date `json:"end"`
    72  }
    73  
    74  func (dr *DateRange) IsZero() (ok bool) {
    75  	ok = dr.Beg.IsZero() && dr.End.IsZero()
    76  	return
    77  }