-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path02-constants.go
142 lines (130 loc) · 3.59 KB
/
02-constants.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package main
import (
"regexp"
"strings"
"unicode"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
"golang.org/x/text/unicode/rangetable"
)
const (
CLDR_VERSION = "31.0.1"
RAW_DIR = "./raw-data"
SUPPLEMENTARY_DIR = "./data-supplementary/date-translation"
SUPPLEMENTARY_BASE_PATH = "./data-supplementary/base_data.yaml"
JSON_DIR = "./data-json"
GO_CODE_DIR = "./internal/data"
)
var (
nfkcTransformer = transform.Chain(norm.NFKD, norm.NFKC)
unicodeTransformer = transform.Chain(norm.NFKD, runes.Remove(runes.In(unicode.Mn)), norm.NFKC)
apostropheLookAlikeChars = []string{
`\x{2019}`, // right single quotation mark
`\x{02bc}`, // modifier letter apostrophe
`\x{02bb}`, // modifier letter turned comma
`\x{055a}`, // armenian apostrophe
`\x{a78c}`, // latin small letter saltillo
`\x{2032}`, // prime
`\x{2035}`, // reversed prime
`\x{02b9}`, // modifier letter prime
`\x{ff07}`, // fullwidth apostrophe
}
numberChars = []string{
`0-9`,
`\x{0660}-\x{0669}`, // arabic
`\x{0f20}-\x{0f29}`, // tibetan
}
rxLocale = regexp.MustCompile(`-[A-Z0-9]+$`)
rxLocaleCleaner = regexp.MustCompile(`-\w+`)
rxDateOrderPattern = regexp.MustCompile(`([DMY])+\x{200f}*[-/. \t]*([DMY])+\x{200f}*[-/. \t]*([DMY])+`)
rxNotRelativePattern = regexp.MustCompile(`[\+\-]\s*\{0\}`)
rxDefaultMonthPattern = regexp.MustCompile(`^m?[` + strings.Join(numberChars, "") + `]+$`)
rxSanitizeAposthrope = regexp.MustCompile(strings.Join(apostropheLookAlikeChars, "|"))
rxSanitizeDateField = regexp.MustCompile(`\$?\d+|^in|ago$`)
rxAmPmPattern = regexp.MustCompile(`^\s*[AaPp]\s*\.?\s*[Mm]\s*\.?\s*$`)
rxParenthesisPattern = regexp.MustCompile(`[\(\)]`)
rxGoEmptyField = regexp.MustCompile(`(?m)^.*\{\s*\},?$\n*`)
rxGoZeroField = regexp.MustCompile(`(?m)^.*(false|0|nil),?$\n*`)
rxGoRegexImport = regexp.MustCompile(`(?m)^\s*import "github.com/markusmobius/go-dateparser/internal/regexp"\s*$`)
rxPythonCaptureGroup = regexp.MustCompile(`\\(\d+)`)
rxGoCaptureGroup = regexp.MustCompile(`\$\{?(\d+)\}?`)
rxParentheses = regexp.MustCompile(`[\(\)]`)
rxCharsetFilter = regexp.MustCompile(`^[\P{L}\p{N}_]+$`)
rxNbsp = regexp.MustCompile(`\x{a0}`)
importantTokens = []string{"+", ":", ".", " ", "-", "/", "am", "pm", "utc", "gmt", "z"}
commonChars = rangetable.New([]rune("0123456789:(){}'.qamp ")...)
// Languages with insufficient translation data are excluded
excludedLanguages = map[string]struct{}{
"cu": {},
"kkj": {},
"nds": {},
"prg": {},
"tk": {},
"vai": {},
"vai-Latn": {},
"vai-Vaii": {},
"vo": {},
}
enMonthNames = []string{
"january",
"february",
"march",
"april",
"may",
"june",
"july",
"august",
"september",
"october",
"november",
"december",
}
enDayNames = []string{
"sunday",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday",
}
enDateFields = []string{
"year",
"month",
"week",
"day",
"hour",
"minute",
"second",
"1 year ago",
"0 year ago",
"in 1 year",
"1 month ago",
"0 month ago",
"in 1 month",
"1 week ago",
"0 week ago",
"in 1 week",
"1 day ago",
"0 day ago",
"in 1 day",
"0 hour ago",
"0 minute ago",
"0 second ago",
"in $1 year",
"$1 year ago",
"in $1 month",
"$1 month ago",
"in $1 week",
"$1 week ago",
"in $1 day",
"$1 day ago",
"in $1 hour",
"$1 hour ago",
"in $1 minute",
"$1 minute ago",
"in $1 second",
"$1 second ago",
}
)