Class: DateTime
- Inherits:
-
Object
- Object
- DateTime
- Defined in:
- lib/mo2tex/extensions/date_time.rb
Constant Summary collapse
- ITWDAYS =
[ 'domenica', 'lunedì', 'martedì', 'mercoledì', 'giovedì', 'venerdì', 'sabato', ]
- FIRST_MIDNIGHT =
DateTime.new(0, 1, 1, 0, 0, 0, 0)
Class Method Summary collapse
- .dayfrac_to_dt(frac) ⇒ Object
- .dayfrac_to_dur(frac) ⇒ Object
- .dayfrac_to_hm(frac) ⇒ Object
- .dayfrac_to_hms(frac) ⇒ Object
- .first_midnight ⇒ Object
- .from_it_wday(wday) ⇒ Object
Instance Method Summary collapse
- #day_only ⇒ Object
- #hm_to_s ⇒ Object
- #round_to_ymdhm ⇒ Object
- #to_it_roff_wday ⇒ Object
- #to_it_wday ⇒ Object
Class Method Details
.dayfrac_to_dt(frac) ⇒ Object
41 42 43 |
# File 'lib/mo2tex/extensions/date_time.rb', line 41 def dayfrac_to_dt(frac) return first_midnight + frac.to_r end |
.dayfrac_to_dur(frac) ⇒ Object
54 55 56 |
# File 'lib/mo2tex/extensions/date_time.rb', line 54 def dayfrac_to_dur(frac) return ((frac.to_r*24)*10).round/10.0 end |
.dayfrac_to_hm(frac) ⇒ Object
45 46 47 48 |
# File 'lib/mo2tex/extensions/date_time.rb', line 45 def dayfrac_to_hm(frac) dt = dayfrac_to_dt(frac) return [dt.hour, dt.minute] end |
.dayfrac_to_hms(frac) ⇒ Object
50 51 52 |
# File 'lib/mo2tex/extensions/date_time.rb', line 50 def dayfrac_to_hms(frac) return dayfrac_to_dt(frac).hm_to_s end |
.first_midnight ⇒ Object
37 38 39 |
# File 'lib/mo2tex/extensions/date_time.rb', line 37 def first_midnight return FIRST_MIDNIGHT end |
.from_it_wday(wday) ⇒ Object
58 59 60 61 62 |
# File 'lib/mo2tex/extensions/date_time.rb', line 58 def from_it_wday(wday) result = ITWDAYS.index(wday) raise UnexistentWeekDay, wday unless result return result end |
Instance Method Details
#day_only ⇒ Object
24 25 26 |
# File 'lib/mo2tex/extensions/date_time.rb', line 24 def day_only return self.to_date.to_datetime end |
#hm_to_s ⇒ Object
7 8 9 10 |
# File 'lib/mo2tex/extensions/date_time.rb', line 7 def hm_to_s result = sprintf("%02d:%02d", self.hour, self.minute) return result end |
#round_to_ymdhm ⇒ Object
28 29 30 31 |
# File 'lib/mo2tex/extensions/date_time.rb', line 28 def round_to_ymdhm result = DateTime.new(self.year, self.month, self.day, self.hour, self.min, 0, 0) return result end |
#to_it_roff_wday ⇒ Object
20 21 22 |
# File 'lib/mo2tex/extensions/date_time.rb', line 20 def to_it_roff_wday return to_it_wday.sub(/ì/, "\\(`i") end |
#to_it_wday ⇒ Object
14 15 16 17 18 |
# File 'lib/mo2tex/extensions/date_time.rb', line 14 def to_it_wday result = ITWDAYS[self.wday] raise UnexistentWeekDay, wd.to_s unless result return result end |