go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/core/resources/time.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package resources
     5  
     6  import (
     7  	"time"
     8  
     9  	"go.mondoo.com/cnquery/llx"
    10  )
    11  
    12  func (p *mqlTime) now() (*time.Time, error) {
    13  	// TODO: needs a ticking event where the time gets updated
    14  	res := time.Now()
    15  	return &res, nil
    16  }
    17  
    18  var (
    19  	second = llx.DurationToTime(1)
    20  	minute = llx.DurationToTime(60)
    21  	hour   = llx.DurationToTime(60 * 60)
    22  	day    = llx.DurationToTime(24 * 60 * 60)
    23  )
    24  
    25  func (x *mqlTime) second() (*time.Time, error) {
    26  	return &second, nil
    27  }
    28  
    29  func (x *mqlTime) minute() (*time.Time, error) {
    30  	return &minute, nil
    31  }
    32  
    33  func (x *mqlTime) hour() (*time.Time, error) {
    34  	return &hour, nil
    35  }
    36  
    37  func (x *mqlTime) day() (*time.Time, error) {
    38  	return &day, nil
    39  }
    40  
    41  func (x *mqlTime) today() (*time.Time, error) {
    42  	now := time.Now()
    43  	today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
    44  
    45  	return &today, nil
    46  }
    47  
    48  func (x *mqlTime) tomorrow() (*time.Time, error) {
    49  	cur, _ := x.today()
    50  	res := cur.Add(24 * time.Hour)
    51  
    52  	return &res, nil
    53  }