Class: SimpleDate
- Inherits:
-
Object
- Object
- SimpleDate
- Defined in:
- lib/simple_date.rb,
lib/simple_date/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
-
.indonesia(time) ⇒ Object
Format awal Tahun Bulan Tanggal.
- .indonesiaCustom(time, type) ⇒ Object
- .indonesiaMonthAlphabet(time) ⇒ Object
- .indonesian_day_name(date) ⇒ Object
- .month(numb) ⇒ Object
- .now ⇒ Object
- .system(time) ⇒ Object
Class Method Details
.indonesia(time) ⇒ Object
Format awal Tahun Bulan Tanggal
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/simple_date.rb', line 37 def self.indonesia(time) if !time.nil? tahun = time[0,4] bulan = time[5,2] hari = time[8,2] return "#{hari}-#{bulan}-#{tahun}" else return "" end end |
.indonesiaCustom(time, type) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/simple_date.rb', line 50 def self.indonesiaCustom(time, type) # h = hari, b = bulan, t = tahun # Penggunaan # TimeFormat::indonesiaCustom(time, {:format => 'bht', :operator => '-', :locale => 'en'}) if !time.nil? # tahun = time[6,4] # bulan = time[0,2] # hari = time[3,2] if type[:format] == "bht" bulan, hari, tahun = time.split '/' elsif type[:format] == "hbt" hari, bulan, tahun = time.split '/' end if type[:operator] == '/' if type[:locale] == 'en' return "#{tahun}/#{bulan}/#{hari}" else return "#{hari}/#{bulan}/#{tahun}" end else if type[:locale] == 'en' return "#{tahun}-#{bulan}-#{hari}" else return "#{hari}-#{bulan}-#{tahun}" end end else return "zzz" end end |
.indonesiaMonthAlphabet(time) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/simple_date.rb', line 85 def self.indonesiaMonthAlphabet(time) if !time.nil? tahun = time[0,4] bulan = self.month(time[5,2]) hari = time[8,2] return "#{hari} #{bulan} #{tahun}" else return "" end end |
.indonesian_day_name(date) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/simple_date.rb', line 111 def self.indonesian_day_name(date) y, m, d = date.split '-' is_date = Date.valid_date? y.to_i, m.to_i, d.to_i if is_date hari = date.to_date.wday else hari = -1 end case hari when 1 'Senin' when 2 'Selasa' when 3 'Rabu' when 4 'Kamis' when 5 'Jumat' when 6 'Sabtu' when 0 'Minggu' else 'Unknown Day' end end |
.month(numb) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/simple_date.rb', line 8 def self.month(numb) if numb == '1' or numb == '01' return 'Januari' elsif numb == '2' or numb == '02' return 'Februari' elsif numb == '3' or numb == '03' return 'Maret' elsif numb == '4' or numb == '04' return "April" elsif numb == '5' or numb == '05' return 'Mei' elsif numb == '6' or numb == '06' return "Juni" elsif numb == '7' or numb == '07' return "Juli" elsif numb == '8' or numb == '08' return "Agustus" elsif numb == '9' or numb == '09' return "September" elsif numb == '10' or numb == '010' return "Oktober" elsif numb == '11' or numb == '011' return "November" elsif numb == '12' or numb == '012' return "Desember" end end |
.now ⇒ Object
4 5 6 7 |
# File 'lib/simple_date.rb', line 4 def self.now time = Time.new return time.strftime("%d/%m/%Y") end |
.system(time) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/simple_date.rb', line 99 def self.system(time) if !time.nil? tahun = time[6,4] bulan = time[3,2] hari = time[0,2] return "#{tahun}-#{bulan}-#{hari}" else return "" end end |