<commit_before>package commands

import (
	"fmt"
	"os"
	"regexp"
	"strconv"
	"time"

	. "../interpreter"
)

var timePattern = regexp.MustCompile(
	"^(?:(\\d\\d)?(\\d\\d))?(\\d\\d)(\\d\\d)(?:(\\d\\d)(\\d\\d))(?:\\.(\\d\\d))?$")

func atoiOr(s string, orelse int) int {
	val, err := strconv.Atoi(s)
	if err != nil {
		return orelse
	}
	return val
}

func readTimeStamp(s string) *time.Time {
	m := timePattern.FindStringSubmatch(s)
	if m == nil {
		return nil
	}
	yy, yy_err := strconv.Atoi(m[2])
	if yy_err != nil {
		yy = time.Now().Year() % 100
	}
	cc, cc_err := strconv.Atoi(m[1])
	if cc_err != nil {
		if yy <= 68 {
			cc = 20
		} else {
			cc = 19
		}
	}
	year := yy + cc*100
	month, _ := strconv.Atoi(m[3])
	mday, _ := strconv.Atoi(m[4])
	hour := atoiOr(m[5], 0)
	min := atoiOr(m[6], 0)
	sec := atoiOr(m[7], 0)
	stamp := time.Date(year, time.Month(month), mday, hour, min, sec, 0, time.Local)<commit_msg>For #127 touch: Add TINY datetime-string validation check<commit_after>package commands

import (
	"fmt"
	"os"
	"regexp"
	"strconv"
	"time"

	. "../interpreter"
)

var timePattern = regexp.MustCompile(
	"^(?:(\\d\\d)?(\\d\\d))?(\\d\\d)(\\d\\d)(?:(\\d\\d)(\\d\\d))(?:\\.(\\d\\d))?$")

func atoiOr(s string, orelse int) int {
	val, err := strconv.Atoi(s)
	if err != nil {
		return orelse
	}
	return val
}

func readTimeStamp(s string) *time.Time {
	m := timePattern.FindStringSubmatch(s)
	if m == nil {
		return nil
	}
	yy, yy_err := strconv.Atoi(m[2])
	if yy_err != nil {
		yy = time.Now().Year() % 100
	}
	cc, cc_err := strconv.Atoi(m[1])
	if cc_err != nil {
		if yy <= 68 {
			cc = 20
		} else {
			cc = 19
		}
	} else if cc < 19 {
		return nil
	}
	year := yy + cc*100
	month, _ := strconv.Atoi(m[3])
	if month < 1 || month > 12 {
		return nil
	}
	mday, _ := strconv.Atoi(m[4])
	if mday < 1 || mday > 31 {
		return nil
	}
	hour := atoiOr(m[5], 0)
	if hour < 0 || hour >= 24 {
		return nil
	}
	min := atoiOr(m[6], 0)
	if min < 0 || min >= 60 {
		return nil
	}
	sec := atoiOr(m[7], 0)
	if sec < 0 || sec > 60 {
		return nil
	}
	stamp := time.Date(year, time.Month(month), mday, hour, min, sec, 0, time.Local)
{'fraction_non_alphanumeric': 0.22117202268431002, 'fraction_numerical': 0.031190926275992438, 'mean_word_length': 2.8144144144144145, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6370784', 'n_tokens_mistral': 1062, 'n_tokens_neox': 983, 'n_words': 223}