Weighted person names, valid personal ids and date() in both locales #21

Merged
lilleman merged 38 commits from person-ids-date into main 2026-09-18 20:45:51 +02:00
2 changed files with 13 additions and 10 deletions
Showing only changes of commit 396ae3bcd2 - Show all commits
+12 -9
View File
@@ -472,17 +472,14 @@ func iban(r rng, cc string) string {
const dayLayout = "2006-01-02" const dayLayout = "2006-01-02"
// The two instants a layout is proved against: alike in nothing, so a layout that // Alike in no field; layoutDay differs from layoutProbe in its date fields only.
// formats them alike names no field, and one that tells their days apart at the same
// clock names a date field.
var ( var (
layoutProbe = time.Date(2001, 2, 3, 4, 5, 6, 0, time.UTC) layoutProbe = time.Date(2001, 2, 3, 4, 5, 6, 0, time.UTC)
layoutProbe2 = time.Date(2010, 11, 12, 13, 14, 15, 0, time.UTC) layoutProbe2 = time.Date(2010, 11, 12, 13, 14, 15, 0, time.UTC)
layoutDay = time.Date(2010, 11, 12, 4, 5, 6, 0, time.UTC) layoutDay = time.Date(2010, 11, 12, 4, 5, 6, 0, time.UTC)
) )
// layoutArg is the Go layout a quoted arg holds; unquoted, it is refused naming the // layoutArg is the Go layout a quoted arg holds, refused when unquoted or constant.
// quoted spelling, since a layout may carry the comma that splits args.
func layoutArg(a string) (string, error) { func layoutArg(a string) (string, error) {
if len(a) < 2 || a[0] != '\'' || a[len(a)-1] != '\'' { if len(a) < 2 || a[0] != '\'' || a[len(a)-1] != '\'' {
return "", fmt.Errorf("layout %s is not quoted; write '%s'", a, strings.Trim(a, "'")) return "", fmt.Errorf("layout %s is not quoted; write '%s'", a, strings.Trim(a, "'"))
@@ -503,8 +500,8 @@ func layoutOf(a string) string {
return layout return layout
} }
// layoutArity checks a call that ends in a layout takes n args; an unquoted layout // layoutArity checks a call ending in a layout takes n args, naming the quoted
// carrying a comma splits into more, so the error names its quoted spelling. // layout when an unquoted one split into more.
func layoutArity(name string, n int, a []string) error { func layoutArity(name string, n int, a []string) error {
if len(a) == n { if len(a) == n {
return nil return nil
@@ -531,8 +528,14 @@ func dateArgs(_ map[string]node, a []string) error {
if !from.Before(to) { if !from.Before(to) {
return fmt.Errorf("date(from,to,layout): from %s is not before to %s", a[0], a[1]) return fmt.Errorf("date(from,to,layout): from %s is not before to %s", a[0], a[1])
} }
_, err = layoutArg(a[2]) layout, err := layoutArg(a[2])
return err if err != nil {
return err
}
if layoutProbe.Format(layout) == layoutDay.Format(layout) {
return fmt.Errorf("date(from,to,layout): '%s' names no date field; write time('%s')", layout, layout)
}
return nil
} }
func timeArg(_ map[string]node, a []string) error { func timeArg(_ map[string]node, a []string) error {
+1 -1
View File
@@ -243,7 +243,7 @@ func (t *table) proveNamesInsideParent() error {
for r := 0; r < t.rows(); r++ { for r := 0; r < t.rows(); r++ {
k := t.cell(r, t.parent) + "\t" + t.cell(r, t.name) k := t.cell(r, t.parent) + "\t" + t.cell(r, t.name)
if first, dup := inside[k]; dup { if first, dup := inside[k]; dup {
return fmt.Errorf("%s line %d: name %q repeats line %d inside %s %q; a name selects one row inside its parent", t.file, r+2, t.cell(r, t.name), first+2, t.columns[t.parent], t.cell(r, t.parent)) return fmt.Errorf("%s line %d: name %q repeats line %d inside %s %q; a name selects one row inside its parent; drop one, or add a key column", t.file, r+2, t.cell(r, t.name), first+2, t.columns[t.parent], t.cell(r, t.parent))
} }
inside[k] = r inside[k] = r
} }