<commit_before>package streamtools

import (
	"github.com/bitly/go-simplejson"
	"log"
	"time"
)

func Date(outChan chan *simplejson.Json, RuleChan chan *simplejson.Json) {

	rule := <-RuleChan
	fmtString, err := rule.Get("fmtString").String()
	if err != nil {
		log.Fatal(err.Error())
	}
	msgJson, err := simplejson.NewJson([]byte("{}"))

	now := time.Now()
	// emit today immediately TODO is this cool?
	today := now.Add(-time.Duration(12) * time.Hour).Round(time.Duration(24) * time.Hour)
	msgJson.Set("date", today.Format(fmtString))
	log.Println("[DATEIN] emitting", msgJson)
	outChan <- msgJson
	tomorrow := now.Add(time.Duration(12) * time.Hour).Round(time.Duration(24) * time.Hour)
	d := tomorrow.Sub(now)

	timer := time.NewTimer(d)

	if err != nil {
		log.Fatal(err.Error())
	}

	for {
		select {
		case <-RuleChan:
		case t := <-timer.C:

			msgJson.Set("date", t.Format(fmtString))
			outChan <- msgJson

		}
	}

}<commit_msg>fixed date in. should work with daylight savings and fire forever.<commit_after>package streamtools

import (
	"github.com/bitly/go-simplejson"
	"log"
	"time"
)

func Date(outChan chan *simplejson.Json, RuleChan chan *simplejson.Json) {
	timer := time.NewTimer(time.Duration(0) * time.Second)
	utcLoc, _ := time.LoadLocation("UTC")
	emit := make(chan time.Time, 1)
	msgJson, _ := simplejson.NewJson([]byte("{}"))
	rule := <-RuleChan
	fmtString, err := rule.Get("fmtString").String()
	if err != nil {
		log.Fatal(err.Error())
	}

	for {
		select {
		case <-RuleChan:
		case <-timer.C:
			emit <- time.Now()
		case t := <-emit:
			msgJson.Set("date", t.Format(fmtString))
			log.Println("[DATEIN] emitting", msgJson)
			outChan <- msgJson

			tomorrow := time.Date(t.Year(), t.Month(), t.Day()+1, 0, 0, 0, 0, utcLoc)
			d := tomorrow.Sub(t)
			timer.Reset(d)
			log.Println("[DATEIN] Next emit time in", d)
		}
	}
}
{'fraction_non_alphanumeric': 0.1827027027027027, 'fraction_numerical': 0.008108108108108109, 'mean_word_length': 3.858267716535433, 'pattern_counts': {'":': 0, '<': 14, '<?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': '6778117', 'n_tokens_mistral': 775, 'n_tokens_neox': 695, 'n_words': 147}