func nextStdChunk()

in pkg/day/day.go [66:192]


func nextStdChunk(from []rune) (to, suffix []rune) {
	if len(from) == 0 {
		to = []rune{}
		suffix = []rune{}
		return
	}

	s := string(from[0])
	old := ""

	switch s {
	case "Y":
		if len(from) >= 4 && string(from[:4]) == "YYYY" {
			old = "YYYY"
		} else if len(from) >= 2 && string(from[:2]) == "YY" {
			old = "YY"
		}
	case "M":
		for i := 4; i > 0; i-- {
			if len(from) >= i {
				switch string(from[:i]) {
				case "MMMM":
					old = "MMMM"
				case "MMM":
					old = "MMM"
				case "MM":
					old = "MM"
				case "M":
					old = "M"
				}
			}
			if old != "" {
				break
			}
		}
	case "D":
		for i := 2; i >= 0; i-- {
			if len(from) >= i {
				switch string(from[:i]) {
				case "DD":
					old = "DD"
				case "D":
					old = "D"
				}
			}
			if old != "" {
				break
			}
		}
	case "H":
		for i := 2; i >= 0; i-- {
			if len(from) >= i {
				switch string(from[:i]) {
				case "HH":
					old = "HH"
				case "H":
					old = "H"
				}
			}
			if old != "" {
				break
			}
		}
	case "h":
		for i := 2; i >= 0; i-- {
			if len(from) >= i {
				switch string(from[:i]) {
				case "hh":
					old = "hh"
				case "h":
					old = "h"
				}
			}
			if old != "" {
				break
			}
		}
	case "m":
		for i := 2; i >= 0; i-- {
			if len(from) >= i {
				switch string(from[:i]) {
				case "mm":
					old = "mm"
				case "m":
					old = "m"
				}
			}
			if old != "" {
				break
			}
		}
	case "s":
		for i := 2; i >= 0; i-- {
			if len(from) >= i {
				switch string(from[:i]) {
				case "ss":
					old = "ss"
				case "s":
					old = "s"
				}
			}
			if old != "" {
				break
			}
		}
	case "A":
		old = "A"
	case "a":
		old = "a"
	case "[":
		if len(from) >= 4 && string(from[:4]) == "[at]" {
			old = "[at]"
		}
	default:
		old = s
	}

	tos, ok := placeholder[old]
	if !ok {
		to = []rune(old)
	} else {
		to = []rune(tos)
	}

	suffix = from[len([]rune(old)):]
	return
}