MCPcopy
hub / github.com/google/mangle / TestTimeFormatCivil

Function TestTimeFormatCivil

functional/functional_test.go:1139–1181  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1137}
1138
1139func TestTimeFormatCivil(t *testing.T) {
1140 // 2024-01-15 10:30:00 UTC
1141 nanos := int64(1705314600000000000)
1142
1143 // America/Los_Angeles is UTC-8 in Jan (PST)
1144 // 10:30 UTC -> 02:30 PST
1145 // Europe/Berlin is UTC+1 in Jan (CET)
1146 // 10:30 UTC -> 11:30 CET
1147
1148 tests := []struct {
1149 tz string
1150 precision string
1151 want string
1152 }{
1153 {"America/Los_Angeles", "/hour", "2024-01-15T02-08:00"},
1154 {"America/Los_Angeles", "/second", "2024-01-15T02:30:00-08:00"},
1155 {"Europe/Berlin", "/hour", "2024-01-15T11+01:00"},
1156 {"Europe/Berlin", "/second", "2024-01-15T11:30:00+01:00"},
1157 {"UTC", "/second", "2024-01-15T10:30:00Z"},
1158 }
1159
1160 for _, test := range tests {
1161 t.Run(fmt.Sprintf("%s-%s", test.tz, test.precision), func(t *testing.T) {
1162 expr := ast.ApplyFn{symbols.TimeFormatCivil, []ast.BaseTerm{
1163 ast.Time(nanos),
1164 ast.String(test.tz),
1165 name(test.precision),
1166 }}
1167 got, err := EvalApplyFn(expr, ast.ConstSubstMap{})
1168 if err != nil {
1169 // time.LoadLocation depends on zoneinfo being present.
1170 // In some build environments it might be missing.
1171 // If error is unknown timezone, skip test?
1172 // But we are in google3, it should work.
1173 t.Fatalf("EvalApplyFn(%v) failed with %v", expr, err)
1174 }
1175 want := ast.String(test.want)
1176 if !got.Equals(want) {
1177 t.Errorf("EvalApplyFn(%v) = %v, want %v", expr, got, want)
1178 }
1179 })
1180 }
1181}
1182
1183func TestTimeFormatInvalid(t *testing.T) {
1184 nanos := int64(1705314600000000000) // 2024-01-15 10:30:00 UTC

Callers

nothing calls this directly

Calls 5

TimeFunction · 0.92
StringFunction · 0.92
EvalApplyFnFunction · 0.85
nameFunction · 0.70
EqualsMethod · 0.65

Tested by

no test coverage detected