(t *testing.T)
| 1137 | } |
| 1138 | |
| 1139 | func 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 | |
| 1183 | func TestTimeFormatInvalid(t *testing.T) { |
| 1184 | nanos := int64(1705314600000000000) // 2024-01-15 10:30:00 UTC |
nothing calls this directly
no test coverage detected