github.com/aacfactory/fns@v1.2.86-0.20240310083819-80d667fc0a17/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  	"time"
    22  )
    23  
    24  func NewTimeRange(left time.Time, right time.Time) (v *TimeRange) {
    25  	v = &TimeRange{
    26  		Beg: left,
    27  		End: right,
    28  	}
    29  	return
    30  }
    31  
    32  // TimeRange
    33  // @title TimeRange
    34  // @description `['2006-01-01T15:04:06Z', '2006-01-01T15:04:06Z')`
    35  type TimeRange struct {
    36  	// Beg
    37  	// @title Beg
    38  	// @description `2006-01-01T15:04:06Z`
    39  	Beg time.Time `json:"beg"`
    40  	// End
    41  	// @title End
    42  	// @description `2006-01-01T15:04:06Z`
    43  	End time.Time `json:"end"`
    44  }
    45  
    46  func (tr *TimeRange) IsZero() (ok bool) {
    47  	ok = tr.Beg.IsZero() && tr.End.IsZero()
    48  	return
    49  }
    50  
    51  func NewDateRange(left Date, right Date) (v *DateRange) {
    52  	v = &DateRange{
    53  		Beg: left,
    54  		End: right,
    55  	}
    56  	return
    57  }
    58  
    59  // DateRange
    60  // @title DateRange
    61  // @description `['2006-01-01', '2006-01-01')`
    62  type DateRange struct {
    63  	// Beg
    64  	// @title Beg
    65  	// @description `2006-01-01`
    66  	Beg Date `json:"beg"`
    67  	// End
    68  	// @title End
    69  	// @description `2006-01-01`
    70  	End Date `json:"end"`
    71  }
    72  
    73  func (dr *DateRange) IsZero() (ok bool) {
    74  	ok = dr.Beg.IsZero() && dr.End.IsZero()
    75  	return
    76  }