read a binary date value
190167
def read_binary_date(fname,fd,length)
      raise CFFormatError.new("Date greater than 8 bytes: #{length}") if length > 3

      nbytes = 1 << length
      buff = fd.read(nbytes)

      CFDate.new(
        case length
        when 0 then # 1 byte CFDate is an error
          raise CFFormatError.new("#{length+1} byte CFDate, error")
        when 1 then # 2 byte CFDate is an error
          raise CFFormatError.new("#{length+1} byte CFDate, error")
        when 2 then
          buff.reverse.unpack("e")[0]
        when 3 then
          buff.reverse.unpack("E")[0]
        end,
        CFDate::TIMESTAMP_APPLE
      )
    end
648092
def to_binary_string(self):
        """"""
        timestamp = datetime_to_timestamp(self.when)
        token = binascii.unhexlify(self.token)
        return struct.pack(self.FORMAT_PREFIX + '{0}s'.format(len(token)),
                           timestamp, len(token), token)
31132
def convertDate(date):
    """"""

    d, t = date.split('T')
    return decimal_date(d, timeobs=t)
463079
def _parse_date(self, raw_value):
        ""
        nday = bytes_to_bint(raw_value) + 678882
        century = (4 * nday - 1) // 146097
        nday = 4 * nday - 1 - 146097 * century
        day = nday // 4

        nday = (4 * day + 3) // 1461
        day = 4 * day + 3 - 1461 * nday
        day = (day + 4) // 4

        month = (5 * day - 3) // 153
        day = 5 * day - 3 - 153 * month
        day = (day + 5) // 5
        year = 100 * century + nday
        if month < 10:
            month += 3
        else:
            month -= 9
            year += 1
        return year, month, day
564003
def date_0utc(date):
    
    return ee.Date.fromYMD(date.get('year'), date.get('month'),
                           date.get('day'))
1360575
def parse_date(self, value):
        
        if isinstance(value, sixmini.string_types):
            return self.str2date(value)
        elif value is None:
            raise TypeError("Unable to parse date from %r" % value)
        elif isinstance(value, sixmini.integer_types):
            return date.fromordinal(value)
        elif isinstance(value, datetime):
            return value.date()
        elif isinstance(value, date):
            return value
        else:
            raise ValueError("Unable to parse date from %r" % value)
836252
def _encode_time(self, value):
        """"""

        if self._kp.version >= (4, 0):
            diff_seconds = int(
                (
                    self._datetime_to_utc(value) -
                    datetime(
                        year=1,
                        month=1,
                        day=1,
                        tzinfo=tz.gettz('UTC')
                    )
                ).total_seconds()
            )
            return base64.b64encode(
                struct.pack('<Q', diff_seconds)
            ).decode('utf-8')
        else:
            return self._datetime_to_utc(value).isoformat()
188585
def _serialize_date(value):
    """"""
    if not isinstance(value, date):
        raise ValueError(u'The received object was not a date: '
                         u'{} {}'.format(type(value), value))
    return value.isoformat()
868128
def parse_date(string, force_datetime=False):
    
    matches = DATE.match(string)
    if not matches:
        return None

    values = dict([
        (
            k,
            v if v[0] in '+-' else int(v)
        ) for k,v in matches.groupdict().items() if v and int(v)
    ])

    if 'timestamp' in values:
        value = datetime.datetime.utcfromtimestamp(0) + datetime.timedelta(
            hours=int(values.get('offset_h', 0)),
            minutes=int(values.get('offset_m', 0)),
            seconds=int(values['timestamp']) / 1000.0
        )
        return value

    # I've made an assumption here, that a DateTime value will not
    # ever be YYYY-MM-DDT00:00:00, which is probably bad. I'm not
    # really sure how to handle this, other than to hard-code the
    # names of the field that are actually Date rather than DateTime.
    if len(values) > 3 or force_datetime:
        return datetime.datetime(**values)

    # Sometimes Xero returns Date(0+0000), so we end up with no
    # values. Return None for this case
    if not values:
        return None

    return datetime.date(**values)
751027
public long readUTCDate()
        throws IOException
    {
        int tag = read();

        if (tag != 'd')
            throw error("expected date at " + codeName(tag));

        long b64 = read();
        long b56 = read();
        long b48 = read();
        long b40 = read();
        long b32 = read();
        long b24 = read();
        long b16 = read();
        long b8 = read();

        return ((b64 << 56) +
            (b56 << 48) +
            (b48 << 40) +
            (b40 << 32) +
            (b32 << 24) +
            (b24 << 16) +
            (b16 << 8) + b8);
    }
691790
function readablizeBytes(bytes) {
  const time = Date.now();
  if (bytes === 0) { return '0 bytes'; }
  const s = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'];
  const e = Math.floor(Math.log(bytes) / Math.log(1024));
  const result = (bytes / Math.pow(1024, e)).toFixed(2) + ' ' + s[e];
  console.info('readablizeBytes', Date.now() - time);
  return result;
}
40754
def read_byte(self, base, offset=0):
        
        fmt = 'B'
        return self._read_int(fmt, base, offset)
516584
private static Date getDateOrNull(JSONObject obj, String field)
			throws JSONException {
		String dateStr = JsonInput.getStringOrNull(obj, field);
		if (dateStr == null)
			return null;
		try {
			if (dateStr.length() >= 5 && dateStr.charAt(4) == '/') {
				return RedmineDateUtils.FULL_DATE_FORMAT.get().parse(dateStr);
			}
			if (dateStr.endsWith("Z")) {
				dateStr = dateStr.substring(0, dateStr.length() - 1)
						+ "GMT-00:00";
			} else {
				final int inset = 6;
				if (dateStr.length() <= inset)
					throw new JSONException("Bad date value " + dateStr);
				String s0 = dateStr.substring(0, dateStr.length() - inset);
				String s1 = dateStr.substring(dateStr.length() - inset,
						dateStr.length());
				dateStr = s0 + "GMT" + s1;
			}
			return RedmineDateUtils.FULL_DATE_FORMAT_V2.get().parse(dateStr);
		} catch (ParseException e) {
			throw new JSONException("Bad date value " + dateStr);
		}
	}
187520
function(oDateValue, sCalendarType, bUTC, bStrict) {
		var oDate,
			iYear = typeof oDateValue.year === "number" ? oDateValue.year : 1970;

		if (oDateValue.valid) {
			if (bUTC || oDateValue.tzDiff !== undefined) {
				oDate = UniversalDate.getInstance(new Date(0), sCalendarType);
				oDate.setUTCEra(oDateValue.era || UniversalDate.getCurrentEra(sCalendarType));
				oDate.setUTCFullYear(iYear);
				oDate.setUTCMonth(oDateValue.month || 0);
				oDate.setUTCDate(oDateValue.day || 1);
				oDate.setUTCHours(oDateValue.hour || 0);
				oDate.setUTCMinutes(oDateValue.minute || 0);
				oDate.setUTCSeconds(oDateValue.second || 0);
				oDate.setUTCMilliseconds(oDateValue.millisecond || 0);
				if (bStrict && (oDateValue.day || 1) !== oDate.getUTCDate()) {
					// check if valid date given - if invalid, day is not the same (31.Apr -> 1.May)
					oDateValue.valid = false;
					oDate = undefined;
				} else {
					if (oDateValue.tzDiff) {
						// Set TZDiff after checking for valid day, as it may switch the day as well
						oDate.setUTCMinutes((oDateValue.minute || 0) + oDateValue.tzDiff);
					}
					if (oDateValue.week !== undefined  && (oDateValue.month === undefined || oDateValue.day === undefined)) {
						//check that the week is only set if the day/month has not been set, because day/month have higher precedence than week
						oDate.setUTCWeek({
							year: oDateValue.weekYear || oDateValue.year,
							week: oDateValue.week
						});

						//add the dayNumberOfWeek to the current day
						if (oDateValue.dayNumberOfWeek !== undefined) {
							oDate.setUTCDate(oDate.getUTCDate() + oDateValue.dayNumberOfWeek - 1);
						}
					}
				}
			} else {
				oDate = UniversalDate.getInstance(new Date(1970, 0, 1, 0, 0, 0), sCalendarType);
				oDate.setEra(oDateValue.era || UniversalDate.getCurrentEra(sCalendarType));
				oDate.setFullYear(iYear);
				oDate.setMonth(oDateValue.month || 0);
				oDate.setDate(oDateValue.day || 1);
				oDate.setHours(oDateValue.hour || 0);
				oDate.setMinutes(oDateValue.minute || 0);
				oDate.setSeconds(oDateValue.second || 0);
				oDate.setMilliseconds(oDateValue.millisecond || 0);
				if (bStrict && (oDateValue.day || 1) !== oDate.getDate()) {
					// check if valid date given - if invalid, day is not the same (31.Apr -> 1.May)
					oDateValue.valid = false;
					oDate = undefined;
				} else if (oDateValue.week !== undefined && (oDateValue.month === undefined || oDateValue.day === undefined)) {
					//check that the week is only set if the day/month has not been set, because day/month have higher precedence than week
					oDate.setWeek({
						year: oDateValue.weekYear || oDateValue.year,
						week: oDateValue.week
					});

					//add the dayNumberOfWeek to the current day
					if (oDateValue.dayNumberOfWeek !== undefined) {
						oDate.setDate(oDate.getDate() + oDateValue.dayNumberOfWeek - 1);
					}
				}
			}

			if (oDateValue.valid) {
				oDate = oDate.getJSDate();
				return oDate;
			}
		}

		return null;
	}
15693
public void toBinDate(TimeZone tz, byte[] bytes, Date value) throws PSQLException {
    long millis = value.getTime();

    if (tz == null) {
      tz = getDefaultTz();
    }
    // It "getOffset" is UNTESTED
    // See org.postgresql.jdbc.AbstractJdbc2Statement.setDate(int, java.sql.Date,
    // java.util.Calendar)
    // The problem is we typically do not know for sure what is the exact required date/timestamp
    // type
    // Thus pgjdbc sticks to text transfer.
    millis += tz.getOffset(millis);

    long secs = toPgSecs(millis / 1000);
    ByteConverter.int4(bytes, 0, (int) (secs / 86400));
  }
516645
def _to_binary(val):
    """"""
    if isinstance(val, text_type):
        return val.encode('utf-8')
    assert isinstance(val, binary_type)
    return val
531319
def date_from_number(self, value):
        
        if not isinstance(value, numbers.Real):
            return None
        delta = datetime.timedelta(days=value)
        return self._null_date + delta