<commit_before>package com.uwetrottmann.trakt5;

import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.JsonSyntaxException;
import com.uwetrottmann.trakt5.enums.ListPrivacy;
import com.uwetrottmann.trakt5.enums.Rating;
import com.uwetrottmann.trakt5.enums.Status;

import java.lang.reflect.Type;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class TraktV2Helper {

    /** trakt uses ISO 8601 dates with milliseconds, mostly in Zulu time (UTC). */
    public static final String DATE_FORMAT_TRAKT = "yyyy-MM-dd'T'HH:mm:ss.SSSX";
    public static final TimeZone DEFAULT_TIME_ZONE_TRAKT = TimeZone.getTimeZone("UTC");

    private static class DateTypeAdapter implements JsonSerializer<Date>, JsonDeserializer<Date> {

        private final SimpleDateFormat iso8601WithMillis;

        private DateTypeAdapter() {
            iso8601WithMillis = new SimpleDateFormat(DATE_FORMAT_TRAKT);
            iso8601WithMillis.setTimeZone(DEFAULT_TIME_ZONE_TRAKT);
        }

        @Override
        public Date deserialize(JsonElement json, Type typeOfT,
                JsonDeserializationContext context) throws JsonParseException {
            synchronized (iso8601WithMillis) {
                try {
                    return iso8601WithMillis.parse(json.getAsString());
                } catch (ParseException e) {
                    throw new JsonSyntaxException(json.getAsString(), e);
                }
            }
        }

        @Override
        public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
            synchronized (iso8601WithMillis) {
                return new JsonPrimitive(iso8601WithMillis.format(src));<commit_msg>Support short dates.<commit_after>package com.uwetrottmann.trakt5;

import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.JsonSyntaxException;
import com.uwetrottmann.trakt5.enums.ListPrivacy;
import com.uwetrottmann.trakt5.enums.Rating;
import com.uwetrottmann.trakt5.enums.Status;

import java.lang.reflect.Type;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class TraktV2Helper {

    /** trakt uses ISO 8601 dates with milliseconds, mostly in Zulu time (UTC). */
    public static final String DATE_FORMAT_TRAKT = "yyyy-MM-dd'T'HH:mm:ss.SSSX";
    public static final String DATE_FORMAT_SHORT = "yyyy-MM-dd";
    public static final TimeZone DEFAULT_TIME_ZONE_TRAKT = TimeZone.getTimeZone("UTC");

    private static class DateTypeAdapter implements JsonSerializer<Date>, JsonDeserializer<Date> {

        private final SimpleDateFormat iso8601WithMillis;
        private final SimpleDateFormat iso8601Date;

        private DateTypeAdapter() {
            iso8601WithMillis = new SimpleDateFormat(DATE_FORMAT_TRAKT);
            iso8601WithMillis.setTimeZone(DEFAULT_TIME_ZONE_TRAKT);
            iso8601Date = new SimpleDateFormat(DATE_FORMAT_SHORT);
            iso8601Date.setTimeZone(DEFAULT_TIME_ZONE_TRAKT);
        }

        @Override
        public Date deserialize(JsonElement json, Type typeOfT,
                JsonDeserializationContext context) throws JsonParseException {
            synchronized (iso8601WithMillis) {
                try {
                    return iso8601WithMillis.parse(json.getAsString());
                } catch (ParseException ignored) {
                }
                try {
                    return iso8601Date.parse(json.getAsString());
                } catch (ParseException e) {
                    throw new JsonSyntaxException(json.getAsString(), e);
                }
            }
        }

        @Override
        public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
            synchronized (iso8601WithMillis) {
                return new JsonPrimitive(iso8601WithMillis.format(src));
{'fraction_non_alphanumeric': 0.07969094922737306, 'fraction_numerical': 0.019867549668874173, 'mean_word_length': 3.214883720930233, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6740407', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1291, 'n_words': 255}