github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/scanners/azure/functions/date_time_epoch.go (about)

     1  package functions
     2  
     3  import (
     4  	"time"
     5  
     6  	smithyTime "github.com/aws/smithy-go/time"
     7  )
     8  
     9  func DateTimeFromEpoch(args ...interface{}) interface{} {
    10  	if len(args) != 1 {
    11  		return nil
    12  	}
    13  
    14  	epoch, ok := args[0].(int)
    15  	if !ok {
    16  		return nil
    17  	}
    18  
    19  	return smithyTime.ParseEpochSeconds(float64(epoch)).Format(time.RFC3339)
    20  }
    21  
    22  func DateTimeToEpoch(args ...interface{}) interface{} {
    23  	if len(args) != 1 {
    24  		return nil
    25  	}
    26  
    27  	dateTime, ok := args[0].(string)
    28  	if !ok {
    29  		return nil
    30  	}
    31  
    32  	parsed, err := time.Parse(time.RFC3339, dateTime)
    33  	if err != nil {
    34  		return nil
    35  	}
    36  
    37  	return int(parsed.Unix())
    38  }