<commit_before>package de.cosmocode.commons;

import java.util.Date;

/**
 * A {@link DateMode} determines the way how to
 * transform a timestamp of type long into a {@link Date} instance.
 *
 * @author <NAME>
 */
public enum DateMode {

    /**
     * Assumes the timestamp is in milliseconds,
     * starting at 1970-01-01T00:00:00GMT
     * as described in {@link Date}.
     */
    JAVA {
        
        @Override
        public Date parse(long value) {
            return new Date(value);
        }
        
        @Override
        public long format(Date date) {
            return date == null ? -1L : date.getTime();
        }
        
    },
    
    /**
     * Assumes the timestamp is in seconds,
     * starting at 1970-01-01T00:00:00GMT.
     */
    UNIXTIME {
        
        @Override
        public Date parse(long value) {
            return new Date(value * 1000L);
        }
        
        @Override
        public long format(Date date) {
            return date == null ? -1L : date.getTime() / 1000L;
        }
        
        
    };
    
    /**
     * Transforms a timestamp into a {@link Date} instance.
     * 
     * @param value the timestamp
     * @return a new {@link Date} instance
     */
    public abstract Date parse(long value);
    
    /**
     * Transforms a {@link Date} instance into a timestamp.
     * 
     * @param date the date instance
     * @return a timestamp created from the date, or -1 if date is null
     */
    public abstract long format(Date date);
    
}<commit_msg>made DateMode implement Comparator<Date> to compare Date based on their specific semantics<commit_after>package de.cosmocode.commons;

import java.util.Comparator;
import java.util.Date;

/**
 * A {@link DateMode} determines the way how to
 * transform a timestamp of type long into a {@link Date} instance.
 *
 * @author <NAME>
 */
public enum DateMode implements Comparator<Date> {

    /**
     * Assumes the timestamp is in milliseconds,
     * starting at 1970-01-01T00:00:00GMT
     * as described in {@link Date}.
     */
    JAVA {
        
        @Override
        public Date parse(long value) {
            return new Date(value);
        }
        
        @Override
        public long format(Date date) {
            return date == null ? -1L : date.getTime();
        }
        
        @Override
        public int compare(Date d1, Date d2) {
            return d1.compareTo(d2);
        }
        
    },
    
    /**
     * Assumes the timestamp is in seconds,
     * starting at 1970-01-01T00:00:00GMT.
     */
    UNIXTIME {
        
        @Override
        public Date parse(long value) {
            return new Date(value * 1000L);
        }
        
        @Override
        public long format(Date date) {
            return date == null ? -1L : date.getTime() / 1000L;
        }
        
        @Override
        public int compare(Date d1, Date d2) {
            final long diff = d1.getTime() - d2.getTime();
            return Math.abs(diff) < 1000L ? 0 : (diff < 0L ? -1 : 1); 
        }
        
    };
    
    /**
     * Transforms a timestamp into a {@link Date} instance.
     * 
     * @param value the timestamp
     * @return a new {@link Date} instance
     */
    public abstract Date parse(long value);
    
    /**
     * Transforms a {@link Date} instance into a timestamp.
     * 
     * @param date the date instance
     * @return a timestamp created from the date, or -1 if date is null
     */
    public abstract long format(Date date);

    /**
     * <p>
     *   This implementations returns 0 if the two given
     *   {@link Date}s are equals as defined by the semantics of
     *   this {@link DateMode}. 
     * </p>
     * 
     * {@inheritDoc}
     */
    @Override
    public abstract int compare(Date d1, Date d2);
    
}
{'fraction_non_alphanumeric': 0.10023554043444124, 'fraction_numerical': 0.02538602460088982, 'mean_word_length': 1.6671318911374737, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '4932527', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1094, 'n_words': 366}