<commit_before>use v6;

class Work-time {
	has Int $.id is rw = 0;
	has DateTime $.start is rw = DateTime.now;
	has DateTime $.end is rw = DateTime.now;
	has Bool $.had-lunch is rw = True;

	method next-day {
		$.start.truncated-to('day').later(day => 1);
	}

	method is-next-day (DateTime $dt) {
		return $dt.truncated-to('day') >= self.next-day;
	}

	multi method set (Str $what, DateTime $dt) {
		given $what {
			when /:i start/ {
				$!start = $dt;
				$!end = $!start if $!start > $!end;
			}
			when /:i end/ {
				if $dt < $!start {
					say "Ignoring { $dt } since it's before { self.start }";
					return;
				}
				$!end = $dt;
			}
		}
	}

	multi method set(DateTime $dt = DateTime.now()) {
		if self.is-next-day($dt) {
			self.reset();
			$!start = $dt;
			$!end = $dt;
		}
		elsif $dt > $!end {
			$!end = $dt;
		}
	}

	method get-time (){
		return $!end.Instant - $!start.Instant - ($!had-lunch.Numeric * 30 * 60);
	}

	method get-time-pretty (){
		my $diff = self.get-time;
		# modulus doesn't return negative so append - in case of negative time
		# also modulus does weird things when negative so use absolute values
		return ($diff < 0 ?? '-' !! '') ~ sprintf '%02d:%02d', $diff / 3600, ($diff.abs % 3600) / 60;
	}

	multi method Str () {
		return join("\n", (start => $!start.Str , end => $!end.Str, had-lunch => $!had-lunch.Numeric), (diff => self.get-time-pretty));
	}

	method clone-me returns Work-time:D {
		my $clone = self.clone;
		$clone.reset();
		return $clone;
	}

    method reset {
		$!had-lunch = True;
		$!id = 0;
    }
}
<commit_msg>Reset on start<commit_after>use v6;

class Work-time {
	has Int $.id is rw = 0;
	has DateTime $.start is rw = DateTime.now;
	has DateTime $.end is rw = DateTime.now;
	has Bool $.had-lunch is rw = True;

	method next-day {
		$.start.truncated-to('day').later(day => 1);
	}

	method is-next-day (DateTime $dt) {
		return $dt.truncated-to('day') >= self.next-day;
	}

	multi method set (Str $what, DateTime $dt) {
		given $what {
			when /:i start/ {
                if self.is-next-day($dt) {
                    self.reset();
                }
				$!start = $dt;
				$!end = $!start if $!start > $!end;
			}
			when /:i end/ {
				if $dt < $!start {
					say "Ignoring { $dt } since it's before { self.start }";
					return;
				}
				$!end = $dt;
			}
		}
	}

	multi method set(DateTime $dt = DateTime.now()) {
		if self.is-next-day($dt) {
			self.reset();
			$!start = $dt;
			$!end = $dt;
		}
		elsif $dt > $!end {
			$!end = $dt;
		}
	}

	method get-time (){
		return $!end.Instant - $!start.Instant - ($!had-lunch.Numeric * 30 * 60);
	}

	method get-time-pretty (){
		my $diff = self.get-time;
		# modulus doesn't return negative so append - in case of negative time
		# also modulus does weird things when negative so use absolute values
		return ($diff < 0 ?? '-' !! '') ~ sprintf '%02d:%02d', $diff / 3600, ($diff.abs % 3600) / 60;
	}

	multi method Str () {
		return join("\n", (start => $!start.Str , end => $!end.Str, had-lunch => $!had-lunch.Numeric), (diff => self.get-time-pretty));
	}

	method clone-me returns Work-time:D {
		my $clone = self.clone;
		$clone.reset();
		return $clone;
	}

    method reset {
		$!had-lunch = True;
		$!id = 0;
    }
}

{'fraction_non_alphanumeric': 0.18676561533704392, 'fraction_numerical': 0.01422387136672851, 'mean_word_length': 2.4859913793103448, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '6371156', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1245, 'n_words': 335}