<commit_before>package funcs

import (
	"context"
	"fmt"
	"strconv"
	"strings"
	"sync"
	gotime "time"

	"github.com/hairyhenderson/gomplate/v3/conv"
	"github.com/hairyhenderson/gomplate/v3/time"
)

var (
	timeNS     *TimeFuncs
	timeNSInit sync.Once
)

// TimeNS -
func TimeNS() *TimeFuncs {
	timeNSInit.Do(func() {
		timeNS = &TimeFuncs{
			ANSIC:       gotime.ANSIC,
			UnixDate:    gotime.UnixDate,
			RubyDate:    gotime.RubyDate,
			RFC822:      gotime.RFC822,
			RFC822Z:     gotime.RFC822Z,
			RFC850:      gotime.RFC850,
			RFC1123:     gotime.RFC1123,
			RFC1123Z:    gotime.RFC1123Z,
			RFC3339:     gotime.RFC3339,
			RFC3339Nano: gotime.RFC3339Nano,
			Kitchen:     gotime.Kitchen,
			Stamp:       gotime.Stamp,
			StampMilli:  gotime.StampMilli,
			StampMicro:  gotime.StampMicro,
			StampNano:   gotime.StampNano,
		}
	})
	return timeNS
}

// AddTimeFuncs -
func AddTimeFuncs(f map[string]interface{}) {
	for k, v := range CreateTimeFuncs(context.Background()) {
		f[k] = v
	}
}

// CreateTimeFuncs -
func CreateTimeFuncs(ctx context.Context) map[string]interface{} {
	ns := TimeNS()
	ns.ctx = ctx

	return map[string]interface{}{"time": TimeNS}
}

// TimeFuncs -
type TimeFuncs struct {
	ctx         context.Context
	ANSIC       string
	UnixDate    string
	RubyDate    string
	RFC822      string
	RFC822Z     string
	RFC850      string
	RFC1123     string
	RFC1123Z    string
	RFC3339     string
	RFC3339Nano string
	Kitchen     string
	Stamp       string
	StampMilli  string
	StampMicro  string
	StampNano   string
}

// ZoneName - return the local system's time zone's name
func (f *TimeFuncs) ZoneName() string {
	return time.ZoneName()
}

// ZoneOffset - return the local system's time zone's name
func (f *TimeFuncs) ZoneOffset() int {
	return time.ZoneOffset()
}

// Parse -
func (f *TimeFuncs) Parse(layout string, value interface{}) (gotime.Time, error) {
	return gotime.Parse(layout, conv.ToString(value))
}

// ParseLocal -
func (f *TimeFuncs) ParseLocal(layout string, value interface{}) (gotime.Time, error) {
	return gotime.ParseInLocation(layout, conv.ToString(value), gotime.Local)
}

// ParseInLocation -
func (f *TimeFuncs) ParseInLocation(layout, location string, value interface{}) (gotime.Time, error) {
	loc, err := gotime.LoadLocation(location)
	if err != nil {
		return gotime.Time{}, err
	}
	return gotime.ParseInLocation(layout, conv.ToString(value), loc)
}

// Now -
func (f *TimeFuncs) Now() gotime.Time {<commit_msg>Support changing TZ env var in ParseInLocal function<commit_after>package funcs

import (
	"context"
	"fmt"
	"strconv"
	"strings"
	"sync"
	gotime "time"

	"github.com/hairyhenderson/gomplate/v3/conv"
	"github.com/hairyhenderson/gomplate/v3/env"
	"github.com/hairyhenderson/gomplate/v3/time"
)

var (
	timeNS     *TimeFuncs
	timeNSInit sync.Once
)

// TimeNS -
func TimeNS() *TimeFuncs {
	timeNSInit.Do(func() {
		timeNS = &TimeFuncs{
			ANSIC:       gotime.ANSIC,
			UnixDate:    gotime.UnixDate,
			RubyDate:    gotime.RubyDate,
			RFC822:      gotime.RFC822,
			RFC822Z:     gotime.RFC822Z,
			RFC850:      gotime.RFC850,
			RFC1123:     gotime.RFC1123,
			RFC1123Z:    gotime.RFC1123Z,
			RFC3339:     gotime.RFC3339,
			RFC3339Nano: gotime.RFC3339Nano,
			Kitchen:     gotime.Kitchen,
			Stamp:       gotime.Stamp,
			StampMilli:  gotime.StampMilli,
			StampMicro:  gotime.StampMicro,
			StampNano:   gotime.StampNano,
		}
	})
	return timeNS
}

// AddTimeFuncs -
func AddTimeFuncs(f map[string]interface{}) {
	for k, v := range CreateTimeFuncs(context.Background()) {
		f[k] = v
	}
}

// CreateTimeFuncs -
func CreateTimeFuncs(ctx context.Context) map[string]interface{} {
	ns := TimeNS()
	ns.ctx = ctx

	return map[string]interface{}{"time": TimeNS}
}

// TimeFuncs -
type TimeFuncs struct {
	ctx         context.Context
	ANSIC       string
	UnixDate    string
	RubyDate    string
	RFC822      string
	RFC822Z     string
	RFC850      string
	RFC1123     string
	RFC1123Z    string
	RFC3339     string
	RFC3339Nano string
	Kitchen     string
	Stamp       string
	StampMilli  string
	StampMicro  string
	StampNano   string
}

// ZoneName - return the local system's time zone's name
func (f *TimeFuncs) ZoneName() string {
	return time.ZoneName()
}

// ZoneOffset - return the local system's time zone's name
func (f *TimeFuncs) ZoneOffset() int {
	return time.ZoneOffset()
}

// Parse -
func (f *TimeFuncs) Parse(layout string, value interface{}) (gotime.Time, error) {
	return gotime.Parse(layout, conv.ToString(value))
}

// ParseLocal -
func (f *TimeFuncs) ParseLocal(layout string, value interface{}) (gotime.Time, error) {
	tz := env.Getenv("TZ", "Local")
	return f.ParseInLocation(layout, tz, value)
}

// ParseInLocation -
func (f *TimeFuncs) ParseInLocation(layout, location string, value interface{}) (gotime.Time, error) {
	loc, err := gotime.LoadLocation(location)
	if err != nil {
		return gotime.Time{}, err
	}
	return gotime.ParseInLocation(layout, conv.ToString(value), loc)
}

// Now -
func (f *TimeFuncs) Now() gotime.Time {
{'fraction_non_alphanumeric': 0.11692984209474315, 'fraction_numerical': 0.030981411153308016, 'mean_word_length': 3.4165931156222418, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '5579808', 'n_tokens_mistral': 2086, 'n_tokens_neox': 1902, 'n_words': 415}