summaryrefslogtreecommitdiff
path: root/ext/date/lib
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-03-20 12:44:47 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-03-20 12:44:47 +0000
commit434157444fed90d00d3919e604fbcc9319d97ed6 (patch)
tree3096972e90ded69bad4875b1be8ea556371aed13 /ext/date/lib
parent7bc47c026066831295b3fdf1ed8f7f8bfafef957 (diff)
* ext/date/date_core.c: replacement of implementation of
strftime. It has some limitations that is same as Time's one. [experimental] * ext/date/date_strftime.c: new. * ext/date/lib/date/format.c: removed ruby version of strftime. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31135 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/date/lib')
-rw-r--r--ext/date/lib/date/format.rb202
1 files changed, 0 insertions, 202 deletions
diff --git a/ext/date/lib/date/format.rb b/ext/date/lib/date/format.rb
index 04168ef014..56dfdcfabe 100644
--- a/ext/date/lib/date/format.rb
+++ b/ext/date/lib/date/format.rb
@@ -131,208 +131,6 @@ class Date
end
- def emit(e, f) # :nodoc:
- case e
- when Numeric
- sign = %w(+ + -)[e <=> 0]
- e = e.abs
- end
-
- s = e.to_s
-
- if f[:s] && f[:p] == '0'
- f[:w] -= 1
- end
-
- if f[:s] && f[:p] == "\s"
- s[0,0] = sign
- end
-
- if f[:p] != '-'
- s = s.rjust(f[:w], f[:p])
- end
-
- if f[:s] && f[:p] != "\s"
- s[0,0] = sign
- end
-
- s = s.upcase if f[:u]
- s = s.downcase if f[:d]
- s
- end
-
- def emit_w(e, w, f) # :nodoc:
- f[:w] = [f[:w], w].compact.max
- emit(e, f)
- end
-
- def emit_n(e, w, f) # :nodoc:
- f[:p] ||= '0'
- emit_w(e, w, f)
- end
-
- def emit_sn(e, w, f) # :nodoc:
- if e < 0
- w += 1
- f[:s] = true
- end
- emit_n(e, w, f)
- end
-
- def emit_z(e, w, f) # :nodoc:
- w += 1
- f[:s] = true
- emit_n(e, w, f)
- end
-
- def emit_a(e, w, f) # :nodoc:
- f[:p] ||= "\s"
- emit_w(e, w, f)
- end
-
- def emit_ad(e, w, f) # :nodoc:
- if f[:x]
- f[:u] = true
- f[:d] = false
- end
- emit_a(e, w, f)
- end
-
- def emit_au(e, w, f) # :nodoc:
- if f[:x]
- f[:u] = false
- f[:d] = true
- end
- emit_a(e, w, f)
- end
-
- private :emit, :emit_w, :emit_n, :emit_sn, :emit_z,
- :emit_a, :emit_ad, :emit_au
-
- def strftime(fmt='%F')
- fmt.gsub(/%([-_0^#]+)?(\d+)?([EO]?(?::{1,3}z|.))/m) do
- f = {}
- m = $&
- s, w, c = $1, $2, $3
- if s
- s.scan(/./) do |k|
- case k
- when '-'; f[:p] = '-'
- when '_'; f[:p] = "\s"
- when '0'; f[:p] = '0'
- when '^'; f[:u] = true
- when '#'; f[:x] = true
- end
- end
- end
- if w
- f[:w] = w.to_i
- end
- case c
- when 'A'; emit_ad(DAYNAMES[wday], 0, f)
- when 'a'; emit_ad(ABBR_DAYNAMES[wday], 0, f)
- when 'B'; emit_ad(MONTHNAMES[mon], 0, f)
- when 'b'; emit_ad(ABBR_MONTHNAMES[mon], 0, f)
- when 'C', 'EC'; emit_sn((year / 100).floor, 2, f)
- when 'c', 'Ec'; emit_a(strftime('%a %b %e %H:%M:%S %Y'), 0, f)
- when 'D'; emit_a(strftime('%m/%d/%y'), 0, f)
- when 'd', 'Od'; emit_n(mday, 2, f)
- when 'e', 'Oe'; emit_a(mday, 2, f)
- when 'F'
- if m == '%F'
- format('%.4d-%02d-%02d', year, mon, mday) # 4p
- else
- emit_a(strftime('%Y-%m-%d'), 0, f)
- end
- when 'G'; emit_sn(cwyear, 4, f)
- when 'g'; emit_n(cwyear % 100, 2, f)
- when 'H', 'OH'; emit_n(hour, 2, f)
- when 'h'; emit_ad(strftime('%b'), 0, f)
- when 'I', 'OI'; emit_n((hour % 12).nonzero? || 12, 2, f)
- when 'j'; emit_n(yday, 3, f)
- when 'k'; emit_a(hour, 2, f)
- when 'L'
- f[:p] = nil
- w = f[:w] || 3
- u = 10**w
- emit_n((sec_fraction * u).floor, w, f)
- when 'l'; emit_a((hour % 12).nonzero? || 12, 2, f)
- when 'M', 'OM'; emit_n(min, 2, f)
- when 'm', 'Om'; emit_n(mon, 2, f)
- when 'N'
- f[:p] = nil
- w = f[:w] || 9
- u = 10**w
- emit_n((sec_fraction * u).floor, w, f)
- when 'n'; emit_a("\n", 0, f)
- when 'P'; emit_ad(strftime('%p').downcase, 0, f)
- when 'p'; emit_au(if hour < 12 then 'AM' else 'PM' end, 0, f)
- when 'Q'
- s = ((ajd - UNIX_EPOCH_IN_AJD) / MILLISECONDS_IN_DAY).round
- emit_sn(s, 1, f)
- when 'R'; emit_a(strftime('%H:%M'), 0, f)
- when 'r'; emit_a(strftime('%I:%M:%S %p'), 0, f)
- when 'S', 'OS'; emit_n(sec, 2, f)
- when 's'
- s = ((ajd - UNIX_EPOCH_IN_AJD) / SECONDS_IN_DAY).round
- emit_sn(s, 1, f)
- when 'T'
- if m == '%T'
- format('%02d:%02d:%02d', hour, min, sec) # 4p
- else
- emit_a(strftime('%H:%M:%S'), 0, f)
- end
- when 't'; emit_a("\t", 0, f)
- when 'U', 'W', 'OU', 'OW'
- emit_n(if c[-1,1] == 'U' then wnum0 else wnum1 end, 2, f)
- when 'u', 'Ou'; emit_n(cwday, 1, f)
- when 'V', 'OV'; emit_n(cweek, 2, f)
- when 'v'; emit_a(strftime('%e-%b-%Y'), 0, f)
- when 'w', 'Ow'; emit_n(wday, 1, f)
- when 'X', 'EX'; emit_a(strftime('%H:%M:%S'), 0, f)
- when 'x', 'Ex'; emit_a(strftime('%m/%d/%y'), 0, f)
- when 'Y', 'EY'; emit_sn(year, 4, f)
- when 'y', 'Ey', 'Oy'; emit_n(year % 100, 2, f)
- when 'Z'; emit_au(strftime('%:z'), 0, f)
- when /\A(:{0,3})z/
- t = $1.size
- sign = if offset < 0 then -1 else +1 end
- fr = offset.abs
- ss = fr.div(SECONDS_IN_DAY) # 4p
- hh, ss = ss.divmod(3600)
- mm, ss = ss.divmod(60)
- if t == 3
- if ss.nonzero? then t = 2
- elsif mm.nonzero? then t = 1
- else t = -1
- end
- end
- case t
- when -1
- tail = []
- sep = ''
- when 0
- f[:w] -= 2 if f[:w]
- tail = ['%02d' % mm]
- sep = ''
- when 1
- f[:w] -= 3 if f[:w]
- tail = ['%02d' % mm]
- sep = ':'
- when 2
- f[:w] -= 6 if f[:w]
- tail = ['%02d' % mm, '%02d' % ss]
- sep = ':'
- end
- ([emit_z(sign * hh, 2, f)] + tail).join(sep)
- when '%'; emit_a('%', 0, f)
- when '+'; emit_a(strftime('%a %b %e %H:%M:%S %Z %Y'), 0, f)
- else
- m
- end
- end
- end
-
# alias_method :format, :strftime
def asctime() strftime('%c') end