You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

time.go 856B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package testfixtures
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. var timeFormats = [...]string{
  7. "2006-01-02",
  8. "2006-01-02 15:04",
  9. "2006-01-02 15:04:05",
  10. "20060102",
  11. "20060102 15:04",
  12. "20060102 15:04:05",
  13. "02/01/2006",
  14. "02/01/2006 15:04",
  15. "02/01/2006 15:04:05",
  16. "2006-01-02T15:04-07:00",
  17. "2006-01-02T15:04:05-07:00",
  18. "2006-01-02T15:04:05Z07:00",
  19. "2006-01-02 15:04:05Z07:00",
  20. "2006-01-02T15:04:05Z0700",
  21. "2006-01-02 15:04:05Z0700",
  22. "2006-01-02T15:04:05Z07",
  23. "2006-01-02 15:04:05Z07",
  24. "2006-01-02 15:04:05 MST",
  25. }
  26. func (l *Loader) tryStrToDate(s string) (time.Time, error) {
  27. loc := l.location
  28. if loc == nil {
  29. loc = time.Local
  30. }
  31. for _, f := range timeFormats {
  32. t, err := time.ParseInLocation(f, s, loc)
  33. if err != nil {
  34. continue
  35. }
  36. return t, nil
  37. }
  38. return time.Time{}, fmt.Errorf(`testfixtures: could not convert string "%s" to time`, s)
  39. }