<commit_before>package com.xtremelabs.robolectric.shadows;


import android.text.format.Time;
import android.util.TimeFormatException;
import com.xtremelabs.robolectric.internal.Implementation;
import com.xtremelabs.robolectric.internal.Implements;
import com.xtremelabs.robolectric.internal.RealObject;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Implements(Time.class)
public class ShadowTime {
    @RealObject
    private Time time;

    public void __constructor__() {
        __constructor__(getCurrentTimezone());
    }

    public void __constructor__(String timezone) {
        if (timezone == null) {
            throw new NullPointerException("timezone is null!");
        }
        time.timezone = timezone;
        time.year = 1970;
        time.monthDay = 1;
        time.isDst = -1;
    }

    public void __constructor__(Time other) {
        set(other);
    }

    @Implementation
    public void set(Time other) {
        time.timezone = other.timezone;
        time.second = other.second;
        time.minute = other.minute;
        time.hour = other.hour;
        time.monthDay = other.monthDay;
        time.month = other.month;
        time.year = other.year;
        time.weekDay = other.weekDay;
        time.yearDay = other.yearDay;
        time.isDst = other.isDst;
        time.gmtoff = other.gmtoff;
    }

    @Implementation
    public void setToNow() {
        set(System.currentTimeMillis());
    }

    @Implementation
    public void set(long millis) {
        Calendar c = getCalendar();
        c.setTimeInMillis(millis);<commit_msg>added julian day functions to TimeShadow<commit_after>package com.xtremelabs.robolectric.shadows;


import android.text.format.Time;
import android.util.TimeFormatException;
import com.xtremelabs.robolectric.internal.Implementation;
import com.xtremelabs.robolectric.internal.Implements;
import com.xtremelabs.robolectric.internal.RealObject;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Implements(Time.class)
public class ShadowTime {
    @RealObject
    private Time time;

    public void __constructor__() {
        __constructor__(getCurrentTimezone());
    }

    public void __constructor__(String timezone) {
        if (timezone == null) {
            throw new NullPointerException("timezone is null!");
        }
        time.timezone = timezone;
        time.year = 1970;
        time.monthDay = 1;
        time.isDst = -1;
    }

    public void __constructor__(Time other) {
        set(other);
    }

    @Implementation
    public void set(Time other) {
        time.timezone = other.timezone;
        time.second = other.second;
        time.minute = other.minute;
        time.hour = other.hour;
        time.monthDay = other.monthDay;
        time.month = other.month;
        time.year = other.year;
        time.weekDay = other.weekDay;
        time.yearDay = other.yearDay;
        time.isDst = other.isDst;
        time.gmtoff = other.gmtoff;
    }

    @Implementation
    public void setToNow() {
        set(System.currentTimeMillis());
    }

	
   
	@Implementation
    public static boolean isEpoch(Time time) {
        long millis = time.toMillis(true);
        return getJulianDay(millis, 0) == Time.EPOCH_JULIAN_DAY;
    }

	//TODO: implement DateUtils shadow
	private static final long SECOND_IN_MILLIS = 1000;
    private static final long MINUTE_IN_MILLIS = SECOND_IN_MILLIS * 60;
    private static final long HOUR_IN_MILLIS = MINUTE_IN_MILLIS * 60;
    private static final long DAY_IN_MILLIS = HOUR_IN_MILLIS * 24;
    private static final long WEEK_IN_MILLIS = DAY_IN_MILLIS * 7;
	
    @Implementation
    public static int getJulianDay(long millis, long gmtoff) {
        long offsetMillis = gmtoff * 1000;
		long julianDay = (millis + offsetMillis) / DAY_IN_MILLIS;
		//TODO: implement DateUtils shadow
        //long julianDay = (millis + offsetMillis) / DateUtils.DAY_IN_MILLIS;
        return (int) julianDay + Time.EPOCH_JULIAN_DAY;
    }
	
	@Implementation
	 public long setJulianDay(int julianDay) {
	 
        // Don't bother with the GMT offset since we don't know the correct
        // value for the given Julian day.  Just get close and then adjust
        // the day.
        
		//TODO: implement DateUtils shadow
		//long millis = (julianDay - EPOCH_JULIAN_DAY) * DateUtils.DAY_IN_MILLIS;
		long millis = (julianDay - Time.EPOCH_JULIAN_DAY) * DAY_IN_MILLIS;
        set(millis);

        // Figure out how close we are to the requested Julian day.
        // We can't be off by more than a day.
        int approximateDay = getJulianDay(millis, time.gmtoff);
        int diff = julianDay - approximateDay;
        time.monthDay += diff;

        // Set the time to 12am and re-normalize.
        time.hour = 0;
        time.minute = 0;
        time.second = 0;
        millis = time.normalize(true);
        return millis;
    }
	
    @Implementation
    public void set(long millis) {
        Calendar c = getCalendar();
        c.setTimeInMillis(millis);
{'fraction_non_alphanumeric': 0.09217291944391544, 'fraction_numerical': 0.006284517234812417, 'mean_word_length': 2.690794096978215, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2768829', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1612, 'n_words': 378}