<commit_before>package io.qala.datagen;

import java.time.*;
import java.time.chrono.ChronoLocalDateTime;
import java.time.chrono.ChronoZonedDateTime;
import java.time.temporal.ChronoField;
import java.util.ArrayList;
import java.util.List;

import static io.qala.datagen.RandomShortApi.sample;
import static java.time.temporal.ChronoUnit.HOURS;
import static java.time.temporal.ChronoUnit.SECONDS;
import static java.time.temporal.ChronoUnit.YEARS;

public class RandomDate {
    private Instant from = LocalDateTime.MIN.toInstant(ZoneOffset.UTC);
    private Instant to = LocalDateTime.MAX.toInstant(ZoneOffset.UTC);

    public static RandomDate between(Instant from, Instant to) {
        if (from.isAfter(to))
            throw new IllegalArgumentException("from(" + from + ") cannot be larger than to(" + to + ")");
        RandomDate date = new RandomDate();
        date.from = from;
        date.to = to;
        return date;
    }
    public static RandomDate between(ChronoLocalDateTime from, ChronoLocalDateTime to) {
        return between(from.toInstant(ZoneOffset.UTC), to.toInstant(ZoneOffset.UTC));
    }

    public static RandomDate between(ChronoZonedDateTime from, ChronoZonedDateTime to) {
        return between(from.toInstant(), to.toInstant());
    }

    public static RandomDate between(LocalDate from, LocalDate to) {
        return between(from.atStartOfDay(), to.atStartOfDay());
    }

    public static RandomDate between(String from, String to) {
        return between(ZonedDateTime.parse(from), ZonedDateTime.parse(to));
    }

    public static RandomDate before(Instant before) {
        return between(LocalDateTime.MIN.toInstant(ZoneOffset.UTC), before);
    }
    public static RandomDate before(ChronoLocalDateTime before) {
        return before(before.toInstant(ZoneOffset.UTC));
    }
    public static RandomDate before(ChronoZonedDateTime before) {
        return before(before.toInstant());
    }

    public static RandomDate beforeNow() {
        return before(Instant.now());
    }

    /** Since specified time till max possible date. */
    public static RandomDate after(Instant after) {
        return between(after, LocalDateTime.MAX.toInstant(ZoneOffset.UTC));
    }

    /** Since specified time till max possible date. */
    public static RandomDate after(ChronoLocalDateTime after) {
        return after(after.toInstant(ZoneOffset.UTC));
    }

    /** Since specified time till max possible date. */
    public static RandomDate after(ChronoZonedDateTime after) {
        return after(after.toInstant());
    }

    public static RandomDate yesterday() {
        return between(LocalDate.now().minusDays(1).atStartOfDay(), LocalDate.now().atStartOfDay().minusSeconds(1));
    }

    public static RandomDate thisYear() {
        return between(LocalDateTime.now().truncatedTo(YEARS), LocalDateTime.now().truncatedTo(YEARS).plusYears(1).minusSeconds(1));
    }

    /** Since specified time till now. */
    public static RandomDate since(Instant since) {
        return between(since, Instant.now(Clock.systemUTC()));
    }

    /** Since specified time till now. */
    public static RandomDate since(ChronoLocalDateTime since) {
        return since(since.toInstant(ZoneId.systemDefault().getRules().getOffset(Instant.now())));
    }

    /** Since specified time till now. */
    public static RandomDate since(ChronoZonedDateTime since) {
        return since(since.toInstant());
    }
    public static RandomDate afterNow() {
        return after(Instant.now());
    }

    public static RandomDate plusMinus100Years() {
        return between(
                LocalDateTime.now().minusYears(100).withDayOfYear(1),
                LocalDateTime.now().plusYears(101).withDayOfYear(1).minusSeconds(1));//last second of the last in 100th year
    }
    public Instant instant() {
        long minSecond = from.getLong(ChronoField.INSTANT_SECONDS);
        long maxSecond = to.getLong(ChronoField.INSTANT_SECONDS);
        int fromNano = from.getNano();
        int toNano = to.getNano();
        long nano = fromNano < toNano ? RandomValue.between(fromNano, toNano).Long() : RandomValue.upTo(toNano).Long();
        return Instant.now().
                with(ChronoField.INSTANT_SECONDS, RandomValue.between(minSecond, maxSecond).Long()).
                with(ChronoField.NANO_OF_SECOND, nano);
    }<commit_msg>Fix nano seconds could be smaller than FROM<commit_after>package io.qala.datagen;

import java.time.*;
import java.time.chrono.ChronoLocalDateTime;
import java.time.chrono.ChronoZonedDateTime;
import java.time.temporal.ChronoField;
import java.util.ArrayList;
import java.util.List;

import static io.qala.datagen.RandomShortApi.sample;
import static java.time.temporal.ChronoUnit.HOURS;
import static java.time.temporal.ChronoUnit.SECONDS;
import static java.time.temporal.ChronoUnit.YEARS;

public class RandomDate {
    private Instant from = LocalDateTime.MIN.toInstant(ZoneOffset.UTC);
    private Instant to = LocalDateTime.MAX.toInstant(ZoneOffset.UTC);

    public static RandomDate between(Instant from, Instant to) {
        if (from.isAfter(to))
            throw new IllegalArgumentException("from(" + from + ") cannot be larger than to(" + to + ")");
        RandomDate date = new RandomDate();
        date.from = from;
        date.to = to;
        return date;
    }
    public static RandomDate between(ChronoLocalDateTime from, ChronoLocalDateTime to) {
        return between(from.toInstant(ZoneOffset.UTC), to.toInstant(ZoneOffset.UTC));
    }

    public static RandomDate between(ChronoZonedDateTime from, ChronoZonedDateTime to) {
        return between(from.toInstant(), to.toInstant());
    }

    public static RandomDate between(LocalDate from, LocalDate to) {
        return between(from.atStartOfDay(), to.atStartOfDay());
    }

    public static RandomDate between(String from, String to) {
        return between(ZonedDateTime.parse(from), ZonedDateTime.parse(to));
    }

    public static RandomDate before(Instant before) {
        return between(LocalDateTime.MIN.toInstant(ZoneOffset.UTC), before);
    }
    public static RandomDate before(ChronoLocalDateTime before) {
        return before(before.toInstant(ZoneOffset.UTC));
    }
    public static RandomDate before(ChronoZonedDateTime before) {
        return before(before.toInstant());
    }

    public static RandomDate beforeNow() {
        return before(Instant.now());
    }

    /** Since specified time till max possible date. */
    public static RandomDate after(Instant after) {
        return between(after, LocalDateTime.MAX.toInstant(ZoneOffset.UTC));
    }

    /** Since specified time till max possible date. */
    public static RandomDate after(ChronoLocalDateTime after) {
        return after(after.toInstant(ZoneOffset.UTC));
    }

    /** Since specified time till max possible date. */
    public static RandomDate after(ChronoZonedDateTime after) {
        return after(after.toInstant());
    }

    public static RandomDate yesterday() {
        return between(LocalDate.now().minusDays(1).atStartOfDay(), LocalDate.now().atStartOfDay().minusSeconds(1));
    }

    public static RandomDate thisYear() {
        return between(LocalDateTime.now().truncatedTo(YEARS), LocalDateTime.now().truncatedTo(YEARS).plusYears(1).minusSeconds(1));
    }

    /** Since specified time till now. */
    public static RandomDate since(Instant since) {
        return between(since, Instant.now(Clock.systemUTC()));
    }

    /** Since specified time till now. */
    public static RandomDate since(ChronoLocalDateTime since) {
        return since(since.toInstant(ZoneId.systemDefault().getRules().getOffset(Instant.now())));
    }

    /** Since specified time till now. */
    public static RandomDate since(ChronoZonedDateTime since) {
        return since(since.toInstant());
    }
    public static RandomDate afterNow() {
        return after(Instant.now());
    }

    public static RandomDate plusMinus100Years() {
        return between(
                LocalDateTime.now().minusYears(100).withDayOfYear(1),
                LocalDateTime.now().plusYears(101).withDayOfYear(1).minusSeconds(1));//last second of the last in 100th year
    }
    public Instant instant() {
        long minSecond = from.getLong(ChronoField.INSTANT_SECONDS);
        long maxSecond = to.getLong(ChronoField.INSTANT_SECONDS);
        int fromNano = from.getNano();
        int toNano = to.getNano();
        long nano = fromNano <= toNano ? RandomValue.between(fromNano, toNano).Long() : RandomValue.upTo(toNano).Long();
        return Instant.now().
                with(ChronoField.INSTANT_SECONDS, RandomValue.between(minSecond, maxSecond).Long()).
                with(ChronoField.NANO_OF_SECOND, nano);
    }
{'fraction_non_alphanumeric': 0.10961866818440523, 'fraction_numerical': 0.004325554923164485, 'mean_word_length': 3.3886113886113884, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5034634', 'n_tokens_mistral': 2601, 'n_tokens_neox': 2496, 'n_words': 565}