<commit_before>package faker

import (
	"math"
	"reflect"
	"strconv"
	"time"
)

type Date struct {
	time.Time
}

func (d *Date) validateYears(t reflect.Kind, y interface{}) int {
	years := 1
	if t == reflect.String {
		years, _ = strconv.Atoi(y.(string))
	} else {
		years = y.(int)
	}

	return years
}

func (d *Date) validateRef(t reflect.Kind, r interface{}) time.Time {
	ref := time.Now()

	if t == reflect.String {
		ref, _ = time.Parse("02-01-2006", r.(string))
	} else if t == reflect.Struct {
		if v, ok := r.(time.Time); ok {
			ref = v
		}

	} else {
		ref = time.Now()
	}
	return ref
}

func (d *Date) validate(params ...interface{}) (years int, ref time.Time) {
	types := kindOf(params...)

	years = 1
	ref = time.Now()

	if len(params) >= 1 {
		years = d.validateYears(types[0], params[0])
	}

	if len(params) > 1 {
		ref = d.validateRef(types[1], params[1])
	}

	return
}

func (d *Date) randomUnix(years int, ref time.Time) int64 {
	// set range
	min := 1000
	max := years * 365 * 24 * 3600 * 1000

	rnd := random(min, max)

	return int64(rnd)
}

// Past_ Generate past date It takes two argument yearsAgo and ref date
func (d *Date) Past_(params ...interface{}) time.Time {
	years, ref := d.validate(params...)
	rnd := d.randomUnix(years, ref)

	// get past
	t := ref.Unix() - int64(rnd)
	past := time.Unix(t, 0)

	return past
}

func (d *Date) Future_(params ...interface{}) time.Time {
	years, ref := d.validate(params...)
	rnd := d.randomUnix(years, ref)

	// get past
	t := ref.Unix() + int64(rnd)
	future := time.Unix(t, 0)

	return future
}

func (d *Date) Between_(from, to string, params ...interface{}) time.Time {
	layout := "02-02-2006"

	kinds := kindOf(params...)
	if len(kinds) >= 1 && kinds[0] == reflect.String {
		layout = params[0].(string)
	}

	fromTime, err := time.Parse(layout, from)
	if err != nil {
		fromTime = time.Unix(time.Now().Unix()-30, 0)
	}

	toTime, err := time.Parse(layout, to)
	if err != nil {
		toTime = time.Now()
	}

	delta := toTime.Unix() - fromTime.Unix()
	newDate := fromTime.Unix() + int64(random(0, int(delta)))

	return time.Unix(newDate, 0)
}

func (d *Date) Recent_(params ...interface{}) time.Time {
	days := 1
	date := time.Now()
	kinds := kindOf(params...)

	if len(kinds) >= 1 && kinds[0] == reflect.Int {
		days = params[0].(int)
	}


	min := int(math.Pow(10, 9))
	if days <= 1 {
		days = 1
	}
	max := days * 24 * 3600 * min
	rnd := random(min, max)

	future := date.UnixNano() - int64(rnd)

	return time.Unix(0, future)
}

func (d *Date) typCtx(options ...interface{}) string {
	typ := "Wide"
	context := false

	types := kindOf(options...)

	if len(types) >= 1 {
		if types[0] == reflect.String {
			v := options[0].(string)
			if v == "Abbr" {
				typ = v
			}
		}
	}

	if len(types) > 1 {
		if types[1] == reflect.Bool {
			v := options[1].(bool)
			if v {
				context = v
			}
		}
	}

	if context {
		typ += "Context"
	}

	return typ
}

func (d *Date) Month_(options ...interface{}) string {
	typ := d.typCtx(options...)
	source := getData("Date", "Month", typ)

	return sample(source)
}

func (d *Date) Weekday_(options ...interface{}) string {
	typ := d.typCtx(options...)
	source := getData("Date", "Weekday", typ)

	return sample(source)
}<commit_msg>remove some method, and refactor<commit_after>package faker

import (
	"math"
	"reflect"
	"time"
)

type Date struct {
	time.Time
}

// Past_ Generate past date It takes two argument yearsAgo and ref date
func (d *Date) Past_(params ...interface{}) time.Time {
	//years, ref := d.validate(params...)

	years := 1
	ref := time.Now()

	types := typeOf(params...)

	if len(types) >= 1 && types[0] == reflect.TypeOf(years) {
		years = params[0].(int)
	}

	if len(types) >= 2 && types[1] == reflect.TypeOf(ref) {
		ref = params[0].(time.Time)
	}

	past := ref.AddDate(-years, 0, 0)
	return past
}

func (d *Date) Future_(params ...interface{}) time.Time {

	years := 1
	ref := time.Now()

	types := typeOf(params...)

	if len(types) >= 1 && types[0] == reflect.TypeOf(years) {
		years = params[0].(int)
	}

	if len(types) >= 2 && types[1] == reflect.TypeOf(ref) {
		ref = params[0].(time.Time)
	}

	future := ref.AddDate(years, 0, 0)
	return future
}

func (d *Date) Between_(from, to string, params ...interface{}) time.Time {
	layout := "02-02-2006"

	kinds := kindOf(params...)
	if len(kinds) >= 1 && kinds[0] == reflect.String {
		layout = params[0].(string)
	}

	fromTime, err := time.Parse(layout, from)
	if err != nil {
		fromTime = time.Unix(time.Now().Unix()-30, 0)
	}

	toTime, err := time.Parse(layout, to)
	if err != nil {
		toTime = time.Now()
	}

	delta := toTime.Unix() - fromTime.Unix()
	newDate := fromTime.Unix() + int64(random(0, int(delta)))

	return time.Unix(newDate, 0)
}

func (d *Date) Recent_(params ...interface{}) time.Time {
	days := 1
	date := time.Now()
	kinds := kindOf(params...)

	if len(kinds) >= 1 && kinds[0] == reflect.Int {
		days = params[0].(int)
	}

	min := int(math.Pow(10, 9))
	if days <= 1 {
		days = 1
	}
	max := days * 24 * 3600 * min
	rnd := random(min, max)

	future := date.UnixNano() - int64(rnd)

	return time.Unix(0, future)
}

func (d *Date) typCtx(options ...interface{}) string {
	typ := "Wide"
	context := false

	types := kindOf(options...)

	if len(types) >= 1 {
		if types[0] == reflect.String {
			v := options[0].(string)
			if v == "Abbr" {
				typ = v
			}
		}
	}

	if len(types) > 1 {
		if types[1] == reflect.Bool {
			v := options[1].(bool)
			if v {
				context = v
			}
		}
	}

	if context {
		typ += "Context"
	}

	return typ
}

func (d *Date) Month_(options ...interface{}) string {
	typ := d.typCtx(options...)
	source := getData("Date", "Month", typ)

	return sample(source)
}

func (d *Date) Weekday_(options ...interface{}) string {
	typ := d.typCtx(options...)
	source := getData("Date", "Weekday", typ)

	return sample(source)
}

// ToJSON Encode name and its fields to JSON.
func (d *Date) ToJSON() (string, error) {
	return ToJSON(d)
}

// ToJSON Encode name and its fields to JSON.
func (d *Date) ToXML() (string, error) {
	return ToJSON(d)
}
{'fraction_non_alphanumeric': 0.19232677360674716, 'fraction_numerical': 0.023978832478915163, 'mean_word_length': 3.092016238159675, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '7066366', 'n_tokens_mistral': 2573, 'n_tokens_neox': 2338, 'n_words': 617}