github.com/argoproj/argo-events@v1.9.1/common/recurrence.go (about) 1 /* 2 Copyright 2018 BlackRock, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package common 18 19 import ( 20 "strings" 21 "time" 22 ) 23 24 const ( 25 exceptionDateTimePrefix = "EXDATE:" 26 dateTimeFormat = "20060102T150405Z" 27 ) 28 29 // ParseExclusionDates parses the exclusion dates from the vals string according to RFC 5545 30 func ParseExclusionDates(vals []string) ([]time.Time, error) { 31 exclusionDates := make([]time.Time, 0) 32 for _, val := range vals { 33 if strings.HasPrefix(val, exceptionDateTimePrefix) { 34 dates, err := parseDateTimes(strings.TrimPrefix(val, exceptionDateTimePrefix)) 35 if err != nil { 36 return nil, err 37 } 38 exclusionDates = append(exclusionDates, dates...) 39 } 40 } 41 return exclusionDates, nil 42 } 43 44 func parseDateTimes(s string) ([]time.Time, error) { 45 res := make([]time.Time, 0) 46 stringDates := strings.Split(s, ",") 47 for _, stringDate := range stringDates { 48 t, err := time.Parse(dateTimeFormat, stringDate) 49 if err != nil { 50 return nil, err 51 } 52 res = append(res, t) 53 } 54 return res, nil 55 }