...

Source file src/github.com/launchdarkly/go-server-sdk-evaluation/v2/ldmodel/parse_values.go

Documentation: github.com/launchdarkly/go-server-sdk-evaluation/v2/ldmodel

     1  package ldmodel
     2  
     3  import (
     4  	"regexp"
     5  	"time"
     6  
     7  	"github.com/launchdarkly/go-sdk-common/v3/ldvalue"
     8  	"github.com/launchdarkly/go-semver"
     9  )
    10  
    11  func parseDateTime(value ldvalue.Value) (time.Time, bool) {
    12  	switch value.Type() {
    13  	case ldvalue.StringType:
    14  		return parseRFC3339TimeUTC(value.StringValue())
    15  	case ldvalue.NumberType:
    16  		return unixMillisToUtcTime(value.Float64Value()), true
    17  	}
    18  	return time.Time{}, false
    19  }
    20  
    21  func unixMillisToUtcTime(unixMillis float64) time.Time {
    22  	return time.Unix(0, int64(unixMillis)*int64(time.Millisecond)).UTC()
    23  }
    24  
    25  func parseRegexp(value ldvalue.Value) *regexp.Regexp {
    26  	if value.IsString() {
    27  		if r, err := regexp.Compile(value.StringValue()); err == nil {
    28  			return r
    29  		}
    30  	}
    31  	return nil
    32  }
    33  
    34  func parseSemVer(value ldvalue.Value) (semver.Version, bool) {
    35  	if value.IsString() {
    36  		versionStr := value.StringValue()
    37  		if sv, err := semver.ParseAs(versionStr, semver.ParseModeAllowMissingMinorAndPatch); err == nil {
    38  			return sv, true
    39  		}
    40  	}
    41  	return semver.Version{}, false
    42  }
    43  

View as plain text