1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
16
17 package index
18
19 import (
20 "fmt"
21 "strings"
22 )
23
24 func unreverseTimeString(s string) string {
25 if !strings.HasPrefix(s, "rt") {
26 panic(fmt.Sprintf("can't unreverse time string: %q", s))
27 }
28 b := make([]byte, 0, len(s)-2)
29 b = appendReverseString(b, s[2:])
30 return string(b)
31 }
32
33 func reverseTimeString(s string) string {
34 b := make([]byte, 0, len(s)+2)
35 b = append(b, 'r')
36 b = append(b, 't')
37 b = appendReverseString(b, s)
38 return string(b)
39 }
40
41 func appendReverseString(b []byte, s string) []byte {
42 for i := 0; i < len(s); i++ {
43 c := s[i]
44 if c >= '0' && c <= '9' {
45 b = append(b, '0'+('9'-c))
46 } else {
47 b = append(b, c)
48 }
49 }
50 return b
51 }