datetime_optional.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (c) 2014 Couchbase, Inc.
  2. // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  3. // except in compliance with the License. You may obtain a copy of the License at
  4. // http://www.apache.org/licenses/LICENSE-2.0
  5. // Unless required by applicable law or agreed to in writing, software distributed under the
  6. // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  7. // either express or implied. See the License for the specific language governing permissions
  8. // and limitations under the License.
  9. package html_char_filter
  10. import (
  11. "time"
  12. "github.com/couchbaselabs/bleve/analysis"
  13. "github.com/couchbaselabs/bleve/analysis/datetime_parsers/flexible_go"
  14. "github.com/couchbaselabs/bleve/registry"
  15. )
  16. const Name = "dateTimeOptional"
  17. const rfc3339NoTimezone = "2006-01-02T15:04:05"
  18. const rfc3339NoTimezoneNoT = "2006-01-02 15:04:05"
  19. const rfc3339NoTime = "2006-01-02"
  20. var layouts = []string{
  21. time.RFC3339Nano,
  22. time.RFC3339,
  23. rfc3339NoTimezone,
  24. rfc3339NoTimezoneNoT,
  25. rfc3339NoTime,
  26. }
  27. func DateTimeParserConstructor(config map[string]interface{}, cache *registry.Cache) (analysis.DateTimeParser, error) {
  28. return flexible_go.NewFlexibleGoDateTimeParser(layouts), nil
  29. }
  30. func init() {
  31. registry.RegisterDateTimeParser(Name, DateTimeParserConstructor)
  32. }