Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
j_platform / app / helpers / j_platform / date_time_helper.rb
Size: Mime:
module JPlatform
  module DateTimeHelper
    def time_to_next_half_hour(time)
      Time.at((time.to_f/30.minutes).ceil * 30.minutes)
    end

    def current_utc()
      Time.now.utc
    end

    def current_utc_unix()
      current_utc().to_i * 1000
    end

    def get_timezone_list(default)
      opts ||= ActiveSupport::TimeZone.all.sort.map do |tz|
        begin
          tz_offset = tz.period_for_local(Time.now).utc_total_offset / 3600
          utc_offset = tz.utc_offset / 3600
          [tz.to_s, tz.name, { 'data-utc_offset' => utc_offset, 'data-utc_total_offset' => tz_offset, 'selected' => tz.name.index(default) }]
        rescue TZInfo::PeriodNotFound
          nil
        end
      end.compact
    end

    def date_format(d)
      d.strftime('%a %d-%m-%Y')
    end

    def time_format(t)
      t.strftime('%I' ':' '%M' ' %p')
    end


    def get_schedule_opts (post = nil)
      selected = post ? post.scheduled_time : Time.zone.now
      selected_time = post ? post.scheduled_time : time_to_next_half_hour(selected)

      schedule = Hash.new
      schedule['current'] = current_utc()
      schedule['selected'] = selected
      schedule['selected_formatted'] = date_format(schedule['selected'])
      schedule['current_formatted'] = date_format(schedule['current'])
      schedule['current_utc_unix'] = current_utc_unix()
      schedule['start'] = schedule['current'] - 12.hours
      schedule['start_formatted'] = date_format(schedule['start'])
      schedule['next_window'] = time_format(selected_time)
      schedule['time_zone'] = ENV['DEFAULT_TIMEZONE'] || 'Eastern'

      schedule
    end

  end
end