papers/utils.go

28 lines
609 B
Go
Raw Permalink Normal View History

package main
import (
"regexp"
"strings"
"time"
)
// IsValidDate checks if the date string is in YYYYMMDD format
func IsValidDate(date string) bool {
// Check basic format with regex
matched, err := regexp.MatchString(`^\d{8}$`, date)
if err != nil || !matched {
return false
}
// Parse date to verify it's a valid date
_, err = time.Parse("20060102", date)
return err == nil
}
// SanitizeFilename replaces invalid filename characters to match arxiva's sanitization
func SanitizeFilename(s string) string {
s = strings.ReplaceAll(s, ":", "_")
s = strings.ReplaceAll(s, " ", "_")
return s
}