Class: Date

Inherits:
Object
  • Object
show all
Includes:
DateTimePrecision
Defined in:
lib/date_time_precision/lib.rb,
lib/date_time_precision/patch/1.8.7/date.rb,
lib/date_time_precision/patch/1.9.2/date.rb,
lib/date_time_precision/patch/1.9.3/date.rb

Direct Known Subclasses

DateTime

Constant Summary collapse

MAX_PRECISION =
DateTimePrecision::DAY

Constants included from DateTimePrecision

DateTimePrecision::DATE_ATTRIBUTES, DateTimePrecision::DATE_ATTRIBUTE_PRECISIONS, DateTimePrecision::DAY, DateTimePrecision::FRAC, DateTimePrecision::HOUR, DateTimePrecision::ISO8601_DATE_FRAGMENTS, DateTimePrecision::ISO8601_TIME_FRAGMENTS, DateTimePrecision::MIN, DateTimePrecision::MONTH, DateTimePrecision::NEW_DEFAULTS, DateTimePrecision::NONE, DateTimePrecision::PATCH_VERSION, DateTimePrecision::SEC, DateTimePrecision::VERSION, DateTimePrecision::YEAR

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DateTimePrecision

#as_json, #fragments, included, #partial_match?, precision, #precision, #precision=, #to_h, #to_json

Class Method Details

.civil(y = nil, m = nil, d = nil, sg = ITALY) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/date_time_precision/patch/1.8.7/date.rb', line 26

def civil(y=nil, m=nil, d=nil, sg=Date::ITALY)
  args = [y,m,d]
  precision = self.precision(args)

  args = normalize_new_args(args)

  unless jd = valid_civil?(*args)
    raise ArgumentError, 'invalid date'
  end

  date = new!(jd_to_ajd(jd, 0, 0), 0, sg)
  date.precision = precision
  date.attributes_set(y,m,d)
  date
end

.civil_origObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/date_time_precision/patch/1.9.3/date.rb', line 30

def civil(y=nil, m=nil, d=nil, sg=Date::ITALY)
  args = [y,m,d]
  precision = self.precision(args)

  args = normalize_new_args(args)

  unless jd = valid_civil?(*args)
    raise ArgumentError, 'invalid date'
  end

  date = new!(jd_to_ajd(jd, 0, 0), 0, sg)
  date.precision = precision
  date.attributes_set(y,m,d)
  date
end

.new(*args) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/date_time_precision/patch/1.8.7/date.rb', line 42

def civil(y=nil, m=nil, d=nil, sg=Date::ITALY)
  args = [y,m,d]
  precision = self.precision(args)

  args = normalize_new_args(args)

  unless jd = valid_civil?(*args)
    raise ArgumentError, 'invalid date'
  end

  date = new!(jd_to_ajd(jd, 0, 0), 0, sg)
  date.precision = precision
  date.attributes_set(y,m,d)
  date
end

.new_origObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/date_time_precision/patch/1.9.3/date.rb', line 10

def civil(y=nil, m=nil, d=nil, sg=Date::ITALY)
  args = [y,m,d]
  precision = self.precision(args)

  args = normalize_new_args(args)

  unless jd = valid_civil?(*args)
    raise ArgumentError, 'invalid date'
  end

  date = new!(jd_to_ajd(jd, 0, 0), 0, sg)
  date.precision = precision
  date.attributes_set(y,m,d)
  date
end

.parse(str = '-4712-01-01T00:00:00+00:00', start = ITALY) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/date_time_precision/patch/1.8.7/date.rb', line 10

def parse(str='-4712-01-01T00:00:00+00:00', comp=false, sg=Date::ITALY)
  elem = _parse(str, comp)
  precision = DateTimePrecision::precision(elem)
  d = new_by_frags(elem, sg)
  d.precision = precision
  d
end

.parse_origObject



20
21
22
23
24
25
26
# File 'lib/date_time_precision/patch/1.9.3/date.rb', line 20

def parse(str='-4712-01-01T00:00:00+00:00', comp=false, sg=Date::ITALY)
  elem = _parse(str, comp)
  precision = DateTimePrecision::precision(elem)
  d = new_by_frags(elem, sg)
  d.precision = precision
  d
end

.strptime(date, format = '%F', start = ITALY) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/date_time_precision/patch/1.8.7/date.rb', line 18

def strptime(str='-4712-01-01', fmt='%F', sg=Date::ITALY)
  elem = _strptime(str, fmt)
  precision = DateTimePrecision::precision(elem)
  d = new_by_frags(elem, sg)
  d.precision = precision
  d
end

.strptime_origObject



43
44
45
46
47
48
49
# File 'lib/date_time_precision/patch/1.9.3/date.rb', line 43

def strptime(str='-4712-01-01', fmt='%F', sg=Date::ITALY)
  elem = _strptime(str, fmt)
  precision = DateTimePrecision::precision(elem)
  d = new_by_frags(elem, sg)
  d.precision = precision
  d
end

.utc(*args) ⇒ Object



44
45
46
# File 'lib/date_time_precision/patch/1.8.7/date.rb', line 44

def utc(*args)
  Time.utc(*args).to_date
end

Instance Method Details

#utc?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/date_time_precision/lib.rb', line 14

def utc?
  offset == 0
end

#utc_offsetObject



20
21
22
# File 'lib/date_time_precision/lib.rb', line 20

def utc_offset
  offset.numerator*3600
end