Return start/stop datetime for the quarter as defined by dt.
199858
def quarter(dt):
    
    quarters = rrule.rrule(
       rrule.MONTHLY,
       bymonth = (1, 4, 7, 10),
       bysetpos = -1,
       dtstart = datetime(dt.year, 1, 1),
       count = 8
    )
    first_day = quarters.before(dt, True)
    last_day = quarters.after(dt) - relativedelta.relativedelta(days=1)
    return (first_day, last_day)
907271
def datetime_to_year_quarter(dt):
    
    year = dt.year
    quarter = int(math.ceil(float(dt.month)/3))
    return (year, quarter)
845164
def date_from_quarter(base_date, ordinal, year):
    
    interval = 3
    month_start = interval * (ordinal - 1)
    if month_start < 0:
        month_start = 9
    month_end = month_start + interval
    if month_start == 0:
        month_start = 1
    return [
        datetime(year, month_start, 1),
        datetime(year, month_end, calendar.monthrange(year, month_end)[1])
    ]
708690
def daterange_start(value):
    ''''''
    if not value:
        return None
    elif isinstance(value, datetime):
        return value.date()
    elif isinstance(value, date):
        return value

    result = parse_dt(value).date()
    dashes = value.count('-')

    if dashes >= 2:
        return result
    elif dashes == 1:
        # Year/Month only
        return result.replace(day=1)
    else:
        # Year only
        return result.replace(day=1, month=1)
227949
def end_time(self):
        """"""
        try:
            return self.start_time + SCAN_DURATION[self.sector]
        except KeyError:
            return self.start_time
1184021
def get_start_time(self):
        
        start_time = c_double()
        self.library.get_start_time.argtypes = [POINTER(c_double)]
        self.library.get_start_time.restype = None
        self.library.get_start_time(byref(start_time))
        return start_time.value
478078
def get_end_balance(self, after: date) -> Decimal:
        
        # create a new date without hours
        #date_corrected = datetimeutils.end_of_day(after)
        datum = Datum()
        datum.from_date(after)
        datum.end_of_day()
        #log(DEBUG, "getting balance on %s", date_corrected)
        return self.get_balance_on(datum.value)
1073559
def __quarters(self, from_date=None):
        
        s = Search(using=self._es_conn, index=self._es_index)
        if from_date:
            # Work around to solve conversion problem of '__' to '.' in field name
            q = Q('range')
            q.__setattr__(self._sort_on_field, {'gte': from_date})
            s = s.filter(q)

        # from:to parameters (=> from: 0, size: 0)
        s = s[0:0]

        s.aggs.bucket(self.TIMEFRAME, 'date_histogram', field=self._timeframe_field,
                      interval='quarter', min_doc_count=1)
        response = s.execute()

        quarters = []
        for quarter in response.aggregations[self.TIMEFRAME].buckets:
            period = pandas.Period(quarter.key_as_string, 'Q')
            quarters.append(period)

        return quarters
604504
def end_time(self):
        
        return float(self.strain.start_time + (len(self.strain) - self.total_corruption) / self.sample_rate)
1024718
def ctime(self, fpath=None):
        
        return dtformat(
            datetime.datetime.utcfromtimestamp(
                os.path.getctime(fpath or self.fpath)))
1188468
def quarter_boundaries(quarter):
    
    year, quarter = quarter.split('Q')
    year = int(year)
    quarter = int(quarter)
    first_month_of_quarter = 3 * quarter - 2
    last_month_of_quarter = 3 * quarter
    first_day = date(year, first_month_of_quarter, 1)
    last_day = date(year, last_month_of_quarter, monthrange(year, last_month_of_quarter)[1])
    return first_day, last_day
922215
def _getAbsoluteTime(self, start, delay):
        
        return start + datetime.timedelta(days=0, seconds=delay)
956355
def _generate_linear_range(start, end, periods):
    """"""
    import cftime

    total_seconds = (end - start).total_seconds()
    values = np.linspace(0., total_seconds, periods, endpoint=True)
    units = 'seconds since {}'.format(format_cftime_datetime(start))
    calendar = start.calendar
    return cftime.num2date(values, units=units, calendar=calendar,
                           only_use_cftime_datetimes=True)
1258697
function(d, range){
		"use strict";

		var start = new Date(d.getFullYear(), 0);
		var stop = null;
		if (range instanceof Date) {
			stop = new Date(range.getFullYear(), 0);
		} else {
			stop = new Date(d.getFullYear()+range, 0);
		}

		return d3.time.years(Math.min(start, stop), Math.max(start, stop));
	}
619222
def datetime(self, start: int = 2000, end: int = 2035,
                 timezone: Optional[str] = None) -> DateTime:
        
        datetime_obj = datetime.combine(
            date=self.date(start, end),
            time=self.time(),
        )
        if timezone:
            if not pytz:
                raise ImportError('Timezones are supported only with pytz')
            tz = pytz.timezone(timezone)
            datetime_obj = tz.localize(datetime_obj)

        return datetime_obj
3475
public static function getQuarter($quarter = 'current')
    {

        $response['startDate']  = null;
        $response['endDate']    = null;

        switch ($quarter)
        {
            case 'current': // current quarter
                $currentMonth   = date('m');
                $currentYear    = date('Y');

                if($currentMonth >= 1 && $currentMonth <= 3)
                {
                    $response['startDate']  = strtotime('1-January-' . $currentYear);  // timestamp or 1-Januray 12:00:00 AM
                    $response['endDate']    = strtotime('1-April-' . $currentYear);  // timestamp or 1-April 12:00:00 AM means end of 31 March
                }
                elseif($currentMonth >= 4 && $currentMonth <= 6)
                {
                    $response['startDate']  = strtotime('1-April-' . $currentYear);  // timestamp or 1-April 12:00:00 AM
                    $response['endDate']    = strtotime('1-July-' . $currentYear);  // timestamp or 1-July 12:00:00 AM means end of 30 June
                }
                elseif($currentMonth >= 7 && $currentMonth <= 9)
                {
                    $response['startDate']  = strtotime('1-July-' . $currentYear);  // timestamp or 1-July 12:00:00 AM
                    $response['endDate']    = strtotime('1-October-' . $currentYear);  // timestamp or 1-October 12:00:00 AM means end of 30 September
                }
                elseif($currentMonth >= 10 && $currentMonth <= 12)
                {
                    $response['startDate']  = strtotime('1-October-' . $currentYear);  // timestamp or 1-October 12:00:00 AM
                    $response['endDate']    = strtotime('1-January-' . ($currentYear + 1));  // timestamp or 1-January Next year 12:00:00 AM means end of 31 December this year
                }
                break;

            case 'last': // daily, get values of last day
                $currentMonth = date('m');
                $currentYear = date('Y');

                if($currentMonth >= 1 && $currentMonth <= 3)
                {
                    $response['startDate']  = strtotime('1-October-' . ($currentYear - 1));  // timestamp or 1-October Last Year 12:00:00 AM
                    $response['endDate']    = strtotime('1-January-' . $currentYear);  // // timestamp or 1-January  12:00:00 AM means end of 31 December Last year
                }
                elseif($currentMonth >= 4 && $currentMonth <= 6)
                {
                    $response['startDate']  = strtotime('1-January-' . $currentYear);  // timestamp or 1-Januray 12:00:00 AM
                    $response['endDate']    = strtotime('1-April-' . $currentYear);  // timestamp or 1-April 12:00:00 AM means end of 31 March
                }
                elseif($currentMonth >= 7 && $currentMonth <= 9)
                {
                    $response['startDate']  = strtotime('1-April-' . $currentYear);  // timestamp or 1-April 12:00:00 AM
                    $response['endDate']    = strtotime('1-July-' . $currentYear);  // timestamp or 1-July 12:00:00 AM means end of 30 June
                }
                elseif($currentMonth >= 10 && $currentMonth <= 12)
                {
                    $response['startDate']  = strtotime('1-July-' . $currentYear);  // timestamp or 1-July 12:00:00 AM
                    $response['endDate']    = strtotime('1-October-' . $currentYear);  // timestamp or 1-October 12:00:00 AM means end of 30 September
                }
                break;
        }

        return $response;
    }
443450
def floor(start, resolution):
    
    if resolution == STEP_10_SEC:
        return datetime(start.year, start.month, start.day, start.hour,
                        start.minute, start.second - (start.second % 10))
    elif resolution == STEP_1_MIN:
        return datetime(start.year, start.month, start.day, start.hour,
                        start.minute)
    elif resolution == STEP_5_MIN:
        return datetime(start.year, start.month, start.day, start.hour,
                        start.minute - (start.minute % 5))
    elif resolution == STEP_1_HOUR:
        return datetime(start.year, start.month, start.day, start.hour)
    elif resolution == STEP_1_DAY:
        return datetime(start.year, start.month, start.day)

    raise ValueError("{resolution} is not a valid resolution. Valid choices "
                     "are {choices}".format(resolution=resolution,
                                            choices=STEP_CHOICES))