Calendar specific methods
Devuelve el día de la fecha de inicio del evento.
# File app/models/tools/calendar.rb, line 49 def day @day || self.starts_at.day end
Devuelve una lista con los día del evento para el mes y el año indicados.
Por ejemplo, para un evento que empieza el 30 de enero y acaba el 2 de
febrero esta función devolverá [30, 31] cuando for_moth = 1
y [1,2] cuando for_month=2
# File app/models/tools/calendar.rb, line 82 def days(for_month=nil, for_year = nil) days_list = [] if self.one_day? days_list = [self.day] else for_month ||= self.starts_at.month for_year ||= self.starts_at.year check_date = Date.parse("#{for_year}-#{for_month}-1").at_beginning_of_month if (self.starts_at.to_date > check_date.end_of_month) || (self.ends_at.to_date < check_date) days_list = [] else # logger.debug "............................. for_month = #{for_month}, for_year = #{for_year}" # logger.debug "............................. ends_at = #{self.ends_at}" first_day = (self.starts_at.to_date >= check_date) ? self.starts_at.day : 1 last_day = (self.ends_at.to_date <= check_date.at_end_of_month) ? self.ends_at.day : check_date.end_of_month.day # logger.debug "....................... first_day = #{first_day}, last_day = #{last_day}" days_list = (first_day..last_day).to_a end end days_list end
Devuelve del primer día del evento para el mes y el año indicados. Por
ejemplo, para un evento que empieza el 30 de enero y acaba el 2 de febrero
esta función devolverá 30 cuando for_moth = 1
y 1 cuando
for_month=2
.
# File app/models/tools/calendar.rb, line 64 def first_day(for_month, for_year) for_date = Date.parse("#{for_year}-#{for_month}-1").at_beginning_of_month if (self.starts_at.to_date > for_date.end_of_month) || (self.ends_at.to_date < for_date) the_day = nil else if self.starts_at.to_date > for_date the_day = self.starts_at.day else the_day = 1 end end the_day end
Indica si el evento tiene especificada la hora de inicio.
# File app/models/tools/calendar.rb, line 34 def has_hour? self.starts_at.strftime('%H%M') != "0000" end
Devuelve el mes de la fecha de inicio del evento.
# File app/models/tools/calendar.rb, line 44 def month @month || self.starts_at.month end
Indica si el evento es de un día o no.
# File app/models/tools/calendar.rb, line 29 def one_day? self.starts_at.to_date.to_s.eql?(self.ends_at.to_date.to_s) end
Valor que se usa para ordenar los eventos dentro de un día. Primero salen los eventos del día, ordendos por hora y al final los eventos que abarcan más de un día.
# File app/models/tools/calendar.rb, line 56 def sort_position pos = self.one_day? ? 0 : 1000 pos += self.starts_at.hour end
Devuelve el año de la fecha de inicio del evento.
# File app/models/tools/calendar.rb, line 39 def year @year || self.starts_at.year end