(t *testing.T)
| 1226 | } |
| 1227 | |
| 1228 | func TestTimeParseCivil(t *testing.T) { |
| 1229 | // 2024-01-15 10:30:00 UTC = 1705314600000000000 |
| 1230 | // 2024-01-15 10:30:00 PST (-08:00) = 1705314600 + 8*3600 = 1705343400 |
| 1231 | // 2024-01-15 10:30:00 CET (+01:00) = 1705314600 - 1*3600 = 1705311000 |
| 1232 | |
| 1233 | tests := []struct { |
| 1234 | timeString string |
| 1235 | tz string |
| 1236 | wantNanos int64 |
| 1237 | }{ |
| 1238 | { |
| 1239 | timeString: "2024-01-15T10:30:00", |
| 1240 | tz: "UTC", |
| 1241 | wantNanos: 1705314600000000000, |
| 1242 | }, |
| 1243 | { |
| 1244 | timeString: "2024-01-15T10:30:00", |
| 1245 | tz: "America/Los_Angeles", |
| 1246 | wantNanos: 1705343400000000000, |
| 1247 | }, |
| 1248 | { |
| 1249 | timeString: "2024-01-15T10:30:00", |
| 1250 | tz: "Europe/Berlin", |
| 1251 | wantNanos: 1705311000000000000, |
| 1252 | }, |
| 1253 | { |
| 1254 | timeString: "2024-01-15T10:30:00.123456789", |
| 1255 | tz: "UTC", |
| 1256 | wantNanos: 1705314600123456789, |
| 1257 | }, |
| 1258 | } |
| 1259 | for _, test := range tests { |
| 1260 | t.Run(fmt.Sprintf("%s-%s", test.timeString, test.tz), func(t *testing.T) { |
| 1261 | expr := ast.ApplyFn{symbols.TimeParseCivil, []ast.BaseTerm{ |
| 1262 | ast.String(test.timeString), |
| 1263 | ast.String(test.tz), |
| 1264 | }} |
| 1265 | got, err := EvalApplyFn(expr, ast.ConstSubstMap{}) |
| 1266 | if err != nil { |
| 1267 | t.Fatalf("EvalApplyFn(%v) failed with %v", expr, err) |
| 1268 | } |
| 1269 | want := ast.Time(test.wantNanos) |
| 1270 | if !got.Equals(want) { |
| 1271 | t.Errorf("EvalApplyFn(%v) = %v, want %v", expr, got, want) |
| 1272 | } |
| 1273 | }) |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | func TestTimeParseCivilNegative(t *testing.T) { |
| 1278 | tests := []struct { |
nothing calls this directly
no test coverage detected