github.com/hashicorp/terraform-plugin-sdk@v1.17.2/helper/validation/time.go (about)

     1  package validation
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
     8  )
     9  
    10  // IsDayOfTheWeek id a SchemaValidateFunc which tests if the provided value is of type string and a valid english day of the week
    11  func IsDayOfTheWeek(ignoreCase bool) schema.SchemaValidateFunc {
    12  	return StringInSlice([]string{
    13  		"Monday",
    14  		"Tuesday",
    15  		"Wednesday",
    16  		"Thursday",
    17  		"Friday",
    18  		"Saturday",
    19  		"Sunday",
    20  	}, ignoreCase)
    21  }
    22  
    23  // IsMonth id a SchemaValidateFunc which tests if the provided value is of type string and a valid english month
    24  func IsMonth(ignoreCase bool) schema.SchemaValidateFunc {
    25  	return StringInSlice([]string{
    26  		"January",
    27  		"February",
    28  		"March",
    29  		"April",
    30  		"May",
    31  		"June",
    32  		"July",
    33  		"August",
    34  		"September",
    35  		"October",
    36  		"November",
    37  		"December",
    38  	}, ignoreCase)
    39  }
    40  
    41  // IsRFC3339Time is a SchemaValidateFunc which tests if the provided value is of type string and a valid RFC33349Time
    42  func IsRFC3339Time(i interface{}, k string) (warnings []string, errors []error) {
    43  	v, ok := i.(string)
    44  	if !ok {
    45  		errors = append(errors, fmt.Errorf("expected type of %q to be string", k))
    46  		return warnings, errors
    47  	}
    48  
    49  	if _, err := time.Parse(time.RFC3339, v); err != nil {
    50  		errors = append(errors, fmt.Errorf("expected %q to be a valid RFC3339 date, got %q: %+v", k, i, err))
    51  	}
    52  
    53  	return warnings, errors
    54  }
    55  
    56  // ValidateRFC3339TimeString is a ValidateFunc that ensures a string parses as time.RFC3339 format
    57  //
    58  // Deprecated: use IsRFC3339Time() instead
    59  func ValidateRFC3339TimeString(i interface{}, k string) (warnings []string, errors []error) {
    60  	return IsRFC3339Time(i, k)
    61  }