Class: Time

Inherits:
Object show all
Defined in:
lib/project/ext/time.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.iso8601(iso8601_string) ⇒ Object


2
3
4
5
6
7
8
# File 'lib/project/ext/time.rb', line 2

def self.iso8601(iso8601_string)
  timestring = iso8601_string.toString
  timestring = timestring.replaceAll("Z", "+00:00")
  timestring = timestring.substring(0, 22) + timestring.substring(23)
  date = Java::Text::SimpleDateFormat.new("yyyy-MM-dd'T'HH:mm:ss+SSS").parse(timestring)
  Time.new(date.getTime())
end

.milliseconds_since_epochObject


10
11
12
# File 'lib/project/ext/time.rb', line 10

def self.milliseconds_since_epoch
  Java::Lang::System.currentTimeMillis.doubleValue
end

Instance Method Details

#strftime(str) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/project/ext/time.rb', line 19

def strftime(str)
  converter = {
    #Ruby => Android
    '%A'  =>  'EEEE',
    '%b'  =>  'MMM',
    '%-e' =>  'd',
    '%-l' =>  'h',
    '%P'  =>  'a',
    '%M'  =>  'mm',
    '%P'  =>  'a',
    '%m'  =>  'MM',
    '%d'  =>  'dd',
    '%Y'  =>  'yyyy'
  }

  converted = str.toString
  converter.each do |k,v|
    converted = converted.replaceAll(k, v)
  end

  formatter = Java::Text::SimpleDateFormat.new(converted)
  formatter.format(self).to_s
end

#today?Boolean

Returns:

  • (Boolean)

14
15
16
17
# File 'lib/project/ext/time.rb', line 14

def today?
  today = Time.now
  (self.year == today.year) && (self.month == today.month) && (self.date == today.date)
end