mirror of
https://github.com/Theodor-Springmann-Stiftung/lenz-web.git
synced 2025-10-29 09:15:33 +00:00
Index functions
This commit is contained in:
@@ -89,13 +89,13 @@ func (p *XMLParser[T]) Serialize(dataholder XMLRootElement[T], path string, late
|
||||
// It deletes all items that have not been parsed in the last commit,
|
||||
// and whose filepath has not been marked as failed.
|
||||
func (p *XMLParser[T]) Cleanup(latest ParseMeta) {
|
||||
todelete := make([]string, 0)
|
||||
todelete := make([]any, 0)
|
||||
toappend := make([]*T, 0)
|
||||
p.Infos.Range(func(key, value interface{}) bool {
|
||||
info := value.(ItemInfo)
|
||||
if !info.Parse.Equals(latest) {
|
||||
if !latest.Failed(info.Source) {
|
||||
todelete = append(todelete, key.(string))
|
||||
todelete = append(todelete, key)
|
||||
} else {
|
||||
item, ok := p.Items.Load(key)
|
||||
if ok {
|
||||
@@ -165,7 +165,7 @@ func (p *XMLParser[T]) Info(id string) ItemInfo {
|
||||
return info.(ItemInfo)
|
||||
}
|
||||
|
||||
func (p *XMLParser[T]) Item(id string) *T {
|
||||
func (p *XMLParser[T]) Item(id any) *T {
|
||||
item, ok := p.Items.Load(id)
|
||||
if !ok {
|
||||
return nil
|
||||
|
||||
@@ -231,17 +231,17 @@ func (xsdd XSDDate) Type() XSDDatetype {
|
||||
}
|
||||
|
||||
func (xsdd *XSDDate) Validate() bool {
|
||||
if xsdd.error {
|
||||
if xsdd.error || len(xsdd.base) == 0 {
|
||||
xsdd.state = Invalid
|
||||
return false
|
||||
}
|
||||
|
||||
xsdd.state = xsdd.inferState()
|
||||
if xsdd.state != Invalid {
|
||||
return true
|
||||
if xsdd.state == Invalid {
|
||||
return false
|
||||
}
|
||||
|
||||
return false
|
||||
return true
|
||||
}
|
||||
|
||||
func (xsdd *XSDDate) parseError(s string) error {
|
||||
@@ -309,6 +309,56 @@ func (xsdd XSDDate) inferState() XSDDatetype {
|
||||
return Invalid
|
||||
}
|
||||
|
||||
func (xsdd XSDDate) Before(other XSDDate) bool {
|
||||
if xsdd.Year < other.Year {
|
||||
return true
|
||||
} else if xsdd.Year > other.Year {
|
||||
return false
|
||||
}
|
||||
|
||||
if xsdd.Month < other.Month {
|
||||
return true
|
||||
} else if xsdd.Month > other.Month {
|
||||
return false
|
||||
}
|
||||
|
||||
if xsdd.Day < other.Day {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (xsddate *XSDDate) Compare(other *XSDDate) int {
|
||||
if !xsddate.Validate() {
|
||||
return -1
|
||||
}
|
||||
|
||||
if !other.Validate() {
|
||||
return 1
|
||||
}
|
||||
|
||||
if xsddate.Year < other.Year {
|
||||
return -1
|
||||
} else if xsddate.Year > other.Year {
|
||||
return 1
|
||||
}
|
||||
|
||||
if xsddate.Month < other.Month {
|
||||
return -1
|
||||
} else if xsddate.Month > other.Month {
|
||||
return 1
|
||||
}
|
||||
|
||||
if xsddate.Day < other.Day {
|
||||
return -1
|
||||
} else if xsddate.Day > other.Day {
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func validDay(i int) bool {
|
||||
if i < 1 || i > 31 {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user