go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/resources/powershell/timestamp.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package powershell
     5  
     6  import (
     7  	"regexp"
     8  	"strconv"
     9  	"time"
    10  )
    11  
    12  var powershellTimestamp = regexp.MustCompile(`Date\((\d+)\)`)
    13  
    14  func PSJsonTimestamp(date string) *time.Time {
    15  	// extract unix seconds
    16  	m := powershellTimestamp.FindStringSubmatch(date)
    17  	if len(m) > 0 {
    18  		i, err := strconv.ParseInt(m[1], 10, 64)
    19  		if err != nil {
    20  			return nil
    21  		}
    22  
    23  		tm := time.Unix(0, i*int64(time.Millisecond))
    24  		return &tm
    25  	}
    26  	return nil
    27  }