# Path: skyfield/timelib.py
# def julian_date(year, month=1, day=1, hour=0, minute=0, second=0.0):
#     """Given a proleptic Gregorian calendar date and time, build a Julian date.
# 
#     The difference between a “Julian day” and a “Julian date” is that
#     the “day” is the integer part, while the “date” includes a fraction
#     indicating the time.
# 
#     """
#     return julian_day(year, month, day) - 0.5 + (
#         second + minute * 60.0 + hour * 3600.0) / DAY_S


import locale
import numpy as np
from datetime import datetime, timedelta
from threading import Lock
from .timelib import julian_date


_lock = Lock()

def _build_legacy_data(deltat_data, deltat_preds, leap_second_dat):
    data_end_time = deltat_data[0, -1]
    i = np.searchsorted(deltat_preds[0], data_end_time, side='right')
    delta_t_recent = np.concatenate([deltat_data, deltat_preds[:,i:]], axis=1)
    leap_dates, leap_offsets = leap_second_dat
    return delta_t_recent, leap_dates, leap_offsets

def parse_deltat_data(fileobj):
    """Parse the United States Naval Observatory ``deltat.data`` file.

    Each line file gives the date and the value of Delta T::

    2016  2  1  68.1577

    This function returns a 2xN array of raw Julian dates and matching
    Delta T values.

    """
    array = np.loadtxt(fileobj)
    year, month, day, delta_t = array.T

# Path: skyfield/timelib.py
# def julian_date(year, month=1, day=1, hour=0, minute=0, second=0.0):
#     """Given a proleptic Gregorian calendar date and time, build a Julian date.
# 
#     The difference between a “Julian day” and a “Julian date” is that
#     the “day” is the integer part, while the “date” includes a fraction
#     indicating the time.
# 
#     """
#     return julian_day(year, month, day) - 0.5 + (
#         second + minute * 60.0 + hour * 3600.0) / DAY_S


# Path: skyfield/io_timescale.py
import locale
import numpy as np
from datetime import datetime, timedelta
from threading import Lock
from .timelib import julian_date



_lock = Lock()

def _build_legacy_data(deltat_data, deltat_preds, leap_second_dat):
    data_end_time = deltat_data[0, -1]
    i = np.searchsorted(deltat_preds[0], data_end_time, side='right')
    delta_t_recent = np.concatenate([deltat_data, deltat_preds[:,i:]], axis=1)
    leap_dates, leap_offsets = leap_second_dat
    return delta_t_recent, leap_dates, leap_offsets

def parse_deltat_data(fileobj):
    """Parse the United States Naval Observatory ``deltat.data`` file.

    Each line file gives the date and the value of Delta T::

    2016  2  1  68.1577

    This function returns a 2xN array of raw Julian dates and matching
    Delta T values.

    """
    array = np.loadtxt(fileobj)
    year, month, day, delta_t = array.T

    return np.array((julian_date(year, month, day), delta_t))