shoesgem 0.1424.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (808) hide show
  1. data/LICENSE +30 -0
  2. data/README.rdoc +31 -0
  3. data/lib/shoes.rb +4 -0
  4. data/shoes/CHANGELOG.txt +21 -0
  5. data/shoes/COPYING.txt +30 -0
  6. data/shoes/README.txt +117 -0
  7. data/shoes/VERSION.txt +1 -0
  8. data/shoes/fonts/Coolvetica.ttf +0 -0
  9. data/shoes/fonts/Lacuna.ttf +0 -0
  10. data/shoes/freetype6.dll +0 -0
  11. data/shoes/lib/shoes/cache.rb +54 -0
  12. data/shoes/lib/shoes/data.rb +39 -0
  13. data/shoes/lib/shoes/help.rb +421 -0
  14. data/shoes/lib/shoes/image.rb +25 -0
  15. data/shoes/lib/shoes/inspect.rb +128 -0
  16. data/shoes/lib/shoes/log.rb +48 -0
  17. data/shoes/lib/shoes/minitar.rb +986 -0
  18. data/shoes/lib/shoes/override.rb +38 -0
  19. data/shoes/lib/shoes/pack.rb +503 -0
  20. data/shoes/lib/shoes/search.rb +46 -0
  21. data/shoes/lib/shoes/setup.rb +329 -0
  22. data/shoes/lib/shoes/shy.rb +131 -0
  23. data/shoes/lib/shoes/shybuilder.rb +44 -0
  24. data/shoes/lib/shoes.rb +522 -0
  25. data/shoes/libcairo-2.dll +0 -0
  26. data/shoes/libeay32.dll +0 -0
  27. data/shoes/libexpat-1.dll +0 -0
  28. data/shoes/libfontconfig-1.dll +0 -0
  29. data/shoes/libgio-2.0-0.dll +0 -0
  30. data/shoes/libglib-2.0-0.dll +0 -0
  31. data/shoes/libgmodule-2.0-0.dll +0 -0
  32. data/shoes/libgobject-2.0-0.dll +0 -0
  33. data/shoes/libgthread-2.0-0.dll +0 -0
  34. data/shoes/libiconv2.dll +0 -0
  35. data/shoes/libjpeg-8.dll +0 -0
  36. data/shoes/libpango-1.0-0.dll +0 -0
  37. data/shoes/libpangocairo-1.0-0.dll +0 -0
  38. data/shoes/libpangoft2-1.0-0.dll +0 -0
  39. data/shoes/libpangowin32-1.0-0.dll +0 -0
  40. data/shoes/libpng14-14.dll +0 -0
  41. data/shoes/libportaudio-2.dll +0 -0
  42. data/shoes/libshoes.dll +0 -0
  43. data/shoes/libssl32.dll +0 -0
  44. data/shoes/libungif4.dll +0 -0
  45. data/shoes/msvcrt-ruby191.dll +0 -0
  46. data/shoes/readline5.dll +0 -0
  47. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/fast_xs.so +0 -0
  48. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/blankslate.rb +63 -0
  49. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/builder.rb +216 -0
  50. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/elements.rb +510 -0
  51. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/htmlinfo.rb +691 -0
  52. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/inspect.rb +103 -0
  53. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/modules.rb +40 -0
  54. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/parse.rb +38 -0
  55. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/tag.rb +202 -0
  56. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/tags.rb +164 -0
  57. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/traverse.rb +838 -0
  58. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/xchar.rb +94 -0
  59. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot.rb +26 -0
  60. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot_scan.so +0 -0
  61. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/add/core.rb +135 -0
  62. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/add/rails.rb +58 -0
  63. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/common.rb +354 -0
  64. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/ext/generator.so +0 -0
  65. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/ext/parser.so +0 -0
  66. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/ext.rb +13 -0
  67. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/version.rb +9 -0
  68. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json.rb +8 -0
  69. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/constants.rb +49 -0
  70. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/database.rb +721 -0
  71. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/driver/dl/api.rb +152 -0
  72. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/driver/dl/driver.rb +307 -0
  73. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/driver/native/driver.rb +219 -0
  74. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/errors.rb +68 -0
  75. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/pragmas.rb +271 -0
  76. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/resultset.rb +180 -0
  77. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/statement.rb +231 -0
  78. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/translator.rb +109 -0
  79. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/value.rb +57 -0
  80. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/version.rb +16 -0
  81. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3.rb +1 -0
  82. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3_api.so +0 -0
  83. data/shoes/ruby/gems/1.9.1/specifications/hpricot-0.8.1.gemspec +32 -0
  84. data/shoes/ruby/gems/1.9.1/specifications/json-shoes-1.1.3.gemspec +34 -0
  85. data/shoes/ruby/gems/1.9.1/specifications/sqlite3-ruby-1.2.5-x86-mswin32.gemspec +46 -0
  86. data/shoes/ruby/lib/English.rb +155 -0
  87. data/shoes/ruby/lib/Win32API.rb +28 -0
  88. data/shoes/ruby/lib/abbrev.rb +103 -0
  89. data/shoes/ruby/lib/base64.rb +91 -0
  90. data/shoes/ruby/lib/benchmark.rb +573 -0
  91. data/shoes/ruby/lib/bigdecimal/jacobian.rb +85 -0
  92. data/shoes/ruby/lib/bigdecimal/ludcmp.rb +86 -0
  93. data/shoes/ruby/lib/bigdecimal/math.rb +237 -0
  94. data/shoes/ruby/lib/bigdecimal/newton.rb +77 -0
  95. data/shoes/ruby/lib/bigdecimal/util.rb +53 -0
  96. data/shoes/ruby/lib/cgi/cookie.rb +144 -0
  97. data/shoes/ruby/lib/cgi/core.rb +786 -0
  98. data/shoes/ruby/lib/cgi/html.rb +1021 -0
  99. data/shoes/ruby/lib/cgi/session/pstore.rb +111 -0
  100. data/shoes/ruby/lib/cgi/session.rb +537 -0
  101. data/shoes/ruby/lib/cgi/util.rb +181 -0
  102. data/shoes/ruby/lib/cgi.rb +274 -0
  103. data/shoes/ruby/lib/cmath.rb +233 -0
  104. data/shoes/ruby/lib/complex.rb +24 -0
  105. data/shoes/ruby/lib/csv.rb +2320 -0
  106. data/shoes/ruby/lib/date/format.rb +1313 -0
  107. data/shoes/ruby/lib/date.rb +1834 -0
  108. data/shoes/ruby/lib/debug.rb +907 -0
  109. data/shoes/ruby/lib/delegate.rb +311 -0
  110. data/shoes/ruby/lib/digest/hmac.rb +274 -0
  111. data/shoes/ruby/lib/digest/sha2.rb +74 -0
  112. data/shoes/ruby/lib/digest.rb +50 -0
  113. data/shoes/ruby/lib/dl/callback.rb +69 -0
  114. data/shoes/ruby/lib/dl/cparser.rb +109 -0
  115. data/shoes/ruby/lib/dl/func.rb +153 -0
  116. data/shoes/ruby/lib/dl/import.rb +215 -0
  117. data/shoes/ruby/lib/dl/pack.rb +173 -0
  118. data/shoes/ruby/lib/dl/stack.rb +146 -0
  119. data/shoes/ruby/lib/dl/struct.rb +213 -0
  120. data/shoes/ruby/lib/dl/types.rb +40 -0
  121. data/shoes/ruby/lib/dl/value.rb +112 -0
  122. data/shoes/ruby/lib/drb/acl.rb +146 -0
  123. data/shoes/ruby/lib/drb/drb.rb +1778 -0
  124. data/shoes/ruby/lib/drb/eq.rb +16 -0
  125. data/shoes/ruby/lib/drb/extserv.rb +71 -0
  126. data/shoes/ruby/lib/drb/extservm.rb +85 -0
  127. data/shoes/ruby/lib/drb/gw.rb +122 -0
  128. data/shoes/ruby/lib/drb/invokemethod.rb +34 -0
  129. data/shoes/ruby/lib/drb/observer.rb +22 -0
  130. data/shoes/ruby/lib/drb/ssl.rb +190 -0
  131. data/shoes/ruby/lib/drb/timeridconv.rb +91 -0
  132. data/shoes/ruby/lib/drb/unix.rb +108 -0
  133. data/shoes/ruby/lib/drb.rb +2 -0
  134. data/shoes/ruby/lib/e2mmap.rb +172 -0
  135. data/shoes/ruby/lib/erb.rb +902 -0
  136. data/shoes/ruby/lib/fileutils.rb +1592 -0
  137. data/shoes/ruby/lib/find.rb +81 -0
  138. data/shoes/ruby/lib/forwardable.rb +270 -0
  139. data/shoes/ruby/lib/ftsearch/analysis/analyzer.rb +16 -0
  140. data/shoes/ruby/lib/ftsearch/analysis/simple_identifier_analyzer.rb +23 -0
  141. data/shoes/ruby/lib/ftsearch/analysis/whitespace_analyzer.rb +22 -0
  142. data/shoes/ruby/lib/ftsearch/document_map_reader.rb +106 -0
  143. data/shoes/ruby/lib/ftsearch/document_map_writer.rb +46 -0
  144. data/shoes/ruby/lib/ftsearch/field_infos.rb +46 -0
  145. data/shoes/ruby/lib/ftsearch/fragment_writer.rb +114 -0
  146. data/shoes/ruby/lib/ftsearch/fulltext_reader.rb +52 -0
  147. data/shoes/ruby/lib/ftsearch/fulltext_writer.rb +75 -0
  148. data/shoes/ruby/lib/ftsearch/suffix_array_reader.rb +275 -0
  149. data/shoes/ruby/lib/ftsearch/suffix_array_writer.rb +99 -0
  150. data/shoes/ruby/lib/ftsearch/util.rb +21 -0
  151. data/shoes/ruby/lib/getoptlong.rb +610 -0
  152. data/shoes/ruby/lib/gserver.rb +253 -0
  153. data/shoes/ruby/lib/i386-mingw32/bigdecimal.so +0 -0
  154. data/shoes/ruby/lib/i386-mingw32/binject.so +0 -0
  155. data/shoes/ruby/lib/i386-mingw32/bloops.so +0 -0
  156. data/shoes/ruby/lib/i386-mingw32/continuation.so +0 -0
  157. data/shoes/ruby/lib/i386-mingw32/coverage.so +0 -0
  158. data/shoes/ruby/lib/i386-mingw32/curses.so +0 -0
  159. data/shoes/ruby/lib/i386-mingw32/digest/bubblebabble.so +0 -0
  160. data/shoes/ruby/lib/i386-mingw32/digest/md5.so +0 -0
  161. data/shoes/ruby/lib/i386-mingw32/digest/rmd160.so +0 -0
  162. data/shoes/ruby/lib/i386-mingw32/digest/sha1.so +0 -0
  163. data/shoes/ruby/lib/i386-mingw32/digest/sha2.so +0 -0
  164. data/shoes/ruby/lib/i386-mingw32/digest.so +0 -0
  165. data/shoes/ruby/lib/i386-mingw32/dl.so +0 -0
  166. data/shoes/ruby/lib/i386-mingw32/enc/big5.so +0 -0
  167. data/shoes/ruby/lib/i386-mingw32/enc/cp949.so +0 -0
  168. data/shoes/ruby/lib/i386-mingw32/enc/emacs_mule.so +0 -0
  169. data/shoes/ruby/lib/i386-mingw32/enc/encdb.so +0 -0
  170. data/shoes/ruby/lib/i386-mingw32/enc/euc_jp.so +0 -0
  171. data/shoes/ruby/lib/i386-mingw32/enc/euc_kr.so +0 -0
  172. data/shoes/ruby/lib/i386-mingw32/enc/euc_tw.so +0 -0
  173. data/shoes/ruby/lib/i386-mingw32/enc/gb18030.so +0 -0
  174. data/shoes/ruby/lib/i386-mingw32/enc/gb2312.so +0 -0
  175. data/shoes/ruby/lib/i386-mingw32/enc/gbk.so +0 -0
  176. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_1.so +0 -0
  177. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_10.so +0 -0
  178. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_11.so +0 -0
  179. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_13.so +0 -0
  180. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_14.so +0 -0
  181. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_15.so +0 -0
  182. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_16.so +0 -0
  183. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_2.so +0 -0
  184. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_3.so +0 -0
  185. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_4.so +0 -0
  186. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_5.so +0 -0
  187. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_6.so +0 -0
  188. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_7.so +0 -0
  189. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_8.so +0 -0
  190. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_9.so +0 -0
  191. data/shoes/ruby/lib/i386-mingw32/enc/koi8_r.so +0 -0
  192. data/shoes/ruby/lib/i386-mingw32/enc/koi8_u.so +0 -0
  193. data/shoes/ruby/lib/i386-mingw32/enc/shift_jis.so +0 -0
  194. data/shoes/ruby/lib/i386-mingw32/enc/trans/big5.so +0 -0
  195. data/shoes/ruby/lib/i386-mingw32/enc/trans/chinese.so +0 -0
  196. data/shoes/ruby/lib/i386-mingw32/enc/trans/escape.so +0 -0
  197. data/shoes/ruby/lib/i386-mingw32/enc/trans/gb18030.so +0 -0
  198. data/shoes/ruby/lib/i386-mingw32/enc/trans/gbk.so +0 -0
  199. data/shoes/ruby/lib/i386-mingw32/enc/trans/iso2022.so +0 -0
  200. data/shoes/ruby/lib/i386-mingw32/enc/trans/japanese.so +0 -0
  201. data/shoes/ruby/lib/i386-mingw32/enc/trans/japanese_euc.so +0 -0
  202. data/shoes/ruby/lib/i386-mingw32/enc/trans/japanese_sjis.so +0 -0
  203. data/shoes/ruby/lib/i386-mingw32/enc/trans/korean.so +0 -0
  204. data/shoes/ruby/lib/i386-mingw32/enc/trans/single_byte.so +0 -0
  205. data/shoes/ruby/lib/i386-mingw32/enc/trans/transdb.so +0 -0
  206. data/shoes/ruby/lib/i386-mingw32/enc/trans/utf_16_32.so +0 -0
  207. data/shoes/ruby/lib/i386-mingw32/enc/utf_16be.so +0 -0
  208. data/shoes/ruby/lib/i386-mingw32/enc/utf_16le.so +0 -0
  209. data/shoes/ruby/lib/i386-mingw32/enc/utf_32be.so +0 -0
  210. data/shoes/ruby/lib/i386-mingw32/enc/utf_32le.so +0 -0
  211. data/shoes/ruby/lib/i386-mingw32/enc/windows_1251.so +0 -0
  212. data/shoes/ruby/lib/i386-mingw32/etc.so +0 -0
  213. data/shoes/ruby/lib/i386-mingw32/fcntl.so +0 -0
  214. data/shoes/ruby/lib/i386-mingw32/fiber.so +0 -0
  215. data/shoes/ruby/lib/i386-mingw32/ftsearchrt.so +0 -0
  216. data/shoes/ruby/lib/i386-mingw32/gdbm.so +0 -0
  217. data/shoes/ruby/lib/i386-mingw32/iconv.so +0 -0
  218. data/shoes/ruby/lib/i386-mingw32/io/wait.so +0 -0
  219. data/shoes/ruby/lib/i386-mingw32/json/ext/generator.so +0 -0
  220. data/shoes/ruby/lib/i386-mingw32/json/ext/parser.so +0 -0
  221. data/shoes/ruby/lib/i386-mingw32/mathn/complex.so +0 -0
  222. data/shoes/ruby/lib/i386-mingw32/mathn/rational.so +0 -0
  223. data/shoes/ruby/lib/i386-mingw32/nkf.so +0 -0
  224. data/shoes/ruby/lib/i386-mingw32/openssl.so +0 -0
  225. data/shoes/ruby/lib/i386-mingw32/racc/cparse.so +0 -0
  226. data/shoes/ruby/lib/i386-mingw32/rbconfig.rb +196 -0
  227. data/shoes/ruby/lib/i386-mingw32/readline.so +0 -0
  228. data/shoes/ruby/lib/i386-mingw32/ripper.so +0 -0
  229. data/shoes/ruby/lib/i386-mingw32/sdbm.so +0 -0
  230. data/shoes/ruby/lib/i386-mingw32/socket.so +0 -0
  231. data/shoes/ruby/lib/i386-mingw32/stringio.so +0 -0
  232. data/shoes/ruby/lib/i386-mingw32/strscan.so +0 -0
  233. data/shoes/ruby/lib/i386-mingw32/syck.so +0 -0
  234. data/shoes/ruby/lib/i386-mingw32/win32ole.so +0 -0
  235. data/shoes/ruby/lib/i386-mingw32/zlib.so +0 -0
  236. data/shoes/ruby/lib/io/nonblock.rb +23 -0
  237. data/shoes/ruby/lib/ipaddr.rb +813 -0
  238. data/shoes/ruby/lib/irb/cmd/chws.rb +32 -0
  239. data/shoes/ruby/lib/irb/cmd/fork.rb +38 -0
  240. data/shoes/ruby/lib/irb/cmd/help.rb +36 -0
  241. data/shoes/ruby/lib/irb/cmd/load.rb +66 -0
  242. data/shoes/ruby/lib/irb/cmd/nop.rb +38 -0
  243. data/shoes/ruby/lib/irb/cmd/pushws.rb +38 -0
  244. data/shoes/ruby/lib/irb/cmd/subirb.rb +42 -0
  245. data/shoes/ruby/lib/irb/completion.rb +207 -0
  246. data/shoes/ruby/lib/irb/context.rb +255 -0
  247. data/shoes/ruby/lib/irb/ext/change-ws.rb +61 -0
  248. data/shoes/ruby/lib/irb/ext/history.rb +109 -0
  249. data/shoes/ruby/lib/irb/ext/loader.rb +119 -0
  250. data/shoes/ruby/lib/irb/ext/math-mode.rb +36 -0
  251. data/shoes/ruby/lib/irb/ext/multi-irb.rb +240 -0
  252. data/shoes/ruby/lib/irb/ext/save-history.rb +100 -0
  253. data/shoes/ruby/lib/irb/ext/tracer.rb +60 -0
  254. data/shoes/ruby/lib/irb/ext/use-loader.rb +64 -0
  255. data/shoes/ruby/lib/irb/ext/workspaces.rb +55 -0
  256. data/shoes/ruby/lib/irb/extend-command.rb +272 -0
  257. data/shoes/ruby/lib/irb/frame.rb +66 -0
  258. data/shoes/ruby/lib/irb/help.rb +35 -0
  259. data/shoes/ruby/lib/irb/init.rb +288 -0
  260. data/shoes/ruby/lib/irb/input-method.rb +142 -0
  261. data/shoes/ruby/lib/irb/lc/error.rb +29 -0
  262. data/shoes/ruby/lib/irb/lc/help-message +38 -0
  263. data/shoes/ruby/lib/irb/lc/ja/encoding_aliases.rb +8 -0
  264. data/shoes/ruby/lib/irb/lc/ja/error.rb +27 -0
  265. data/shoes/ruby/lib/irb/lc/ja/help-message +39 -0
  266. data/shoes/ruby/lib/irb/locale.rb +195 -0
  267. data/shoes/ruby/lib/irb/magic-file.rb +36 -0
  268. data/shoes/ruby/lib/irb/notifier.rb +144 -0
  269. data/shoes/ruby/lib/irb/output-method.rb +69 -0
  270. data/shoes/ruby/lib/irb/ruby-lex.rb +1188 -0
  271. data/shoes/ruby/lib/irb/ruby-token.rb +270 -0
  272. data/shoes/ruby/lib/irb/slex.rb +282 -0
  273. data/shoes/ruby/lib/irb/src_encoding.rb +4 -0
  274. data/shoes/ruby/lib/irb/version.rb +15 -0
  275. data/shoes/ruby/lib/irb/workspace.rb +108 -0
  276. data/shoes/ruby/lib/irb/ws-for-case-2.rb +14 -0
  277. data/shoes/ruby/lib/irb/xmp.rb +97 -0
  278. data/shoes/ruby/lib/irb.rb +354 -0
  279. data/shoes/ruby/lib/json/add/core.rb +135 -0
  280. data/shoes/ruby/lib/json/add/rails.rb +58 -0
  281. data/shoes/ruby/lib/json/common.rb +354 -0
  282. data/shoes/ruby/lib/json/editor.rb +1371 -0
  283. data/shoes/ruby/lib/json/ext.rb +15 -0
  284. data/shoes/ruby/lib/json/version.rb +9 -0
  285. data/shoes/ruby/lib/json.rb +297 -0
  286. data/shoes/ruby/lib/kconv.rb +282 -0
  287. data/shoes/ruby/lib/logger.rb +732 -0
  288. data/shoes/ruby/lib/mathn.rb +206 -0
  289. data/shoes/ruby/lib/matrix.rb +1381 -0
  290. data/shoes/ruby/lib/minitest/autorun.rb +9 -0
  291. data/shoes/ruby/lib/minitest/mock.rb +37 -0
  292. data/shoes/ruby/lib/minitest/spec.rb +89 -0
  293. data/shoes/ruby/lib/minitest/unit.rb +497 -0
  294. data/shoes/ruby/lib/mkmf.rb +1958 -0
  295. data/shoes/ruby/lib/monitor.rb +265 -0
  296. data/shoes/ruby/lib/mutex_m.rb +91 -0
  297. data/shoes/ruby/lib/net/ftp.rb +981 -0
  298. data/shoes/ruby/lib/net/http.rb +2399 -0
  299. data/shoes/ruby/lib/net/https.rb +136 -0
  300. data/shoes/ruby/lib/net/imap.rb +3500 -0
  301. data/shoes/ruby/lib/net/pop.rb +1000 -0
  302. data/shoes/ruby/lib/net/protocol.rb +382 -0
  303. data/shoes/ruby/lib/net/smtp.rb +1014 -0
  304. data/shoes/ruby/lib/net/telnet.rb +759 -0
  305. data/shoes/ruby/lib/observer.rb +193 -0
  306. data/shoes/ruby/lib/open-uri.rb +832 -0
  307. data/shoes/ruby/lib/open3.rb +98 -0
  308. data/shoes/ruby/lib/openssl/bn.rb +35 -0
  309. data/shoes/ruby/lib/openssl/buffering.rb +242 -0
  310. data/shoes/ruby/lib/openssl/cipher.rb +65 -0
  311. data/shoes/ruby/lib/openssl/digest.rb +61 -0
  312. data/shoes/ruby/lib/openssl/ssl.rb +178 -0
  313. data/shoes/ruby/lib/openssl/x509.rb +155 -0
  314. data/shoes/ruby/lib/openssl.rb +24 -0
  315. data/shoes/ruby/lib/optparse/date.rb +17 -0
  316. data/shoes/ruby/lib/optparse/shellwords.rb +6 -0
  317. data/shoes/ruby/lib/optparse/time.rb +10 -0
  318. data/shoes/ruby/lib/optparse/uri.rb +6 -0
  319. data/shoes/ruby/lib/optparse/version.rb +70 -0
  320. data/shoes/ruby/lib/optparse.rb +1810 -0
  321. data/shoes/ruby/lib/ostruct.rb +145 -0
  322. data/shoes/ruby/lib/pathname.rb +1099 -0
  323. data/shoes/ruby/lib/pp.rb +532 -0
  324. data/shoes/ruby/lib/prettyprint.rb +896 -0
  325. data/shoes/ruby/lib/prime.rb +471 -0
  326. data/shoes/ruby/lib/profile.rb +10 -0
  327. data/shoes/ruby/lib/profiler.rb +59 -0
  328. data/shoes/ruby/lib/pstore.rb +543 -0
  329. data/shoes/ruby/lib/racc/parser.rb +441 -0
  330. data/shoes/ruby/lib/rake/classic_namespace.rb +8 -0
  331. data/shoes/ruby/lib/rake/clean.rb +33 -0
  332. data/shoes/ruby/lib/rake/gempackagetask.rb +97 -0
  333. data/shoes/ruby/lib/rake/loaders/makefile.rb +35 -0
  334. data/shoes/ruby/lib/rake/packagetask.rb +185 -0
  335. data/shoes/ruby/lib/rake/rake_test_loader.rb +5 -0
  336. data/shoes/ruby/lib/rake/rdoctask.rb +147 -0
  337. data/shoes/ruby/lib/rake/runtest.rb +23 -0
  338. data/shoes/ruby/lib/rake/tasklib.rb +23 -0
  339. data/shoes/ruby/lib/rake/testtask.rb +161 -0
  340. data/shoes/ruby/lib/rake/win32.rb +34 -0
  341. data/shoes/ruby/lib/rake.rb +2465 -0
  342. data/shoes/ruby/lib/rational.rb +19 -0
  343. data/shoes/ruby/lib/rbconfig/datadir.rb +24 -0
  344. data/shoes/ruby/lib/rdoc/code_objects.rb +1061 -0
  345. data/shoes/ruby/lib/rdoc/diagram.rb +340 -0
  346. data/shoes/ruby/lib/rdoc/dot.rb +249 -0
  347. data/shoes/ruby/lib/rdoc/generator/chm/chm.rb +100 -0
  348. data/shoes/ruby/lib/rdoc/generator/chm.rb +113 -0
  349. data/shoes/ruby/lib/rdoc/generator/html/common.rb +24 -0
  350. data/shoes/ruby/lib/rdoc/generator/html/frameless.rb +92 -0
  351. data/shoes/ruby/lib/rdoc/generator/html/hefss.rb +150 -0
  352. data/shoes/ruby/lib/rdoc/generator/html/html.rb +769 -0
  353. data/shoes/ruby/lib/rdoc/generator/html/kilmer.rb +151 -0
  354. data/shoes/ruby/lib/rdoc/generator/html/kilmerfactory.rb +427 -0
  355. data/shoes/ruby/lib/rdoc/generator/html/one_page_html.rb +122 -0
  356. data/shoes/ruby/lib/rdoc/generator/html.rb +445 -0
  357. data/shoes/ruby/lib/rdoc/generator/ri.rb +226 -0
  358. data/shoes/ruby/lib/rdoc/generator/texinfo/class.texinfo.erb +44 -0
  359. data/shoes/ruby/lib/rdoc/generator/texinfo/file.texinfo.erb +6 -0
  360. data/shoes/ruby/lib/rdoc/generator/texinfo/method.texinfo.erb +6 -0
  361. data/shoes/ruby/lib/rdoc/generator/texinfo/texinfo.erb +28 -0
  362. data/shoes/ruby/lib/rdoc/generator/texinfo.rb +81 -0
  363. data/shoes/ruby/lib/rdoc/generator/xml/rdf.rb +113 -0
  364. data/shoes/ruby/lib/rdoc/generator/xml/xml.rb +123 -0
  365. data/shoes/ruby/lib/rdoc/generator/xml.rb +117 -0
  366. data/shoes/ruby/lib/rdoc/generator.rb +1082 -0
  367. data/shoes/ruby/lib/rdoc/known_classes.rb +68 -0
  368. data/shoes/ruby/lib/rdoc/markup/attribute_manager.rb +265 -0
  369. data/shoes/ruby/lib/rdoc/markup/formatter.rb +14 -0
  370. data/shoes/ruby/lib/rdoc/markup/fragments.rb +337 -0
  371. data/shoes/ruby/lib/rdoc/markup/inline.rb +101 -0
  372. data/shoes/ruby/lib/rdoc/markup/lines.rb +152 -0
  373. data/shoes/ruby/lib/rdoc/markup/preprocess.rb +75 -0
  374. data/shoes/ruby/lib/rdoc/markup/to_flow.rb +185 -0
  375. data/shoes/ruby/lib/rdoc/markup/to_html.rb +403 -0
  376. data/shoes/ruby/lib/rdoc/markup/to_html_crossref.rb +148 -0
  377. data/shoes/ruby/lib/rdoc/markup/to_latex.rb +328 -0
  378. data/shoes/ruby/lib/rdoc/markup/to_test.rb +50 -0
  379. data/shoes/ruby/lib/rdoc/markup/to_texinfo.rb +69 -0
  380. data/shoes/ruby/lib/rdoc/markup.rb +378 -0
  381. data/shoes/ruby/lib/rdoc/options.rb +638 -0
  382. data/shoes/ruby/lib/rdoc/parser/c.rb +661 -0
  383. data/shoes/ruby/lib/rdoc/parser/f95.rb +1835 -0
  384. data/shoes/ruby/lib/rdoc/parser/perl.rb +165 -0
  385. data/shoes/ruby/lib/rdoc/parser/ruby.rb +2829 -0
  386. data/shoes/ruby/lib/rdoc/parser/simple.rb +38 -0
  387. data/shoes/ruby/lib/rdoc/parser.rb +142 -0
  388. data/shoes/ruby/lib/rdoc/rdoc.rb +293 -0
  389. data/shoes/ruby/lib/rdoc/ri/cache.rb +187 -0
  390. data/shoes/ruby/lib/rdoc/ri/descriptions.rb +156 -0
  391. data/shoes/ruby/lib/rdoc/ri/display.rb +392 -0
  392. data/shoes/ruby/lib/rdoc/ri/driver.rb +669 -0
  393. data/shoes/ruby/lib/rdoc/ri/formatter.rb +616 -0
  394. data/shoes/ruby/lib/rdoc/ri/paths.rb +99 -0
  395. data/shoes/ruby/lib/rdoc/ri/reader.rb +106 -0
  396. data/shoes/ruby/lib/rdoc/ri/util.rb +79 -0
  397. data/shoes/ruby/lib/rdoc/ri/writer.rb +68 -0
  398. data/shoes/ruby/lib/rdoc/ri.rb +8 -0
  399. data/shoes/ruby/lib/rdoc/stats.rb +115 -0
  400. data/shoes/ruby/lib/rdoc/template.rb +64 -0
  401. data/shoes/ruby/lib/rdoc/tokenstream.rb +33 -0
  402. data/shoes/ruby/lib/rdoc.rb +395 -0
  403. data/shoes/ruby/lib/resolv-replace.rb +63 -0
  404. data/shoes/ruby/lib/resolv.rb +2262 -0
  405. data/shoes/ruby/lib/rexml/attlistdecl.rb +62 -0
  406. data/shoes/ruby/lib/rexml/attribute.rb +188 -0
  407. data/shoes/ruby/lib/rexml/cdata.rb +67 -0
  408. data/shoes/ruby/lib/rexml/child.rb +96 -0
  409. data/shoes/ruby/lib/rexml/comment.rb +80 -0
  410. data/shoes/ruby/lib/rexml/doctype.rb +270 -0
  411. data/shoes/ruby/lib/rexml/document.rb +231 -0
  412. data/shoes/ruby/lib/rexml/dtd/attlistdecl.rb +10 -0
  413. data/shoes/ruby/lib/rexml/dtd/dtd.rb +51 -0
  414. data/shoes/ruby/lib/rexml/dtd/elementdecl.rb +17 -0
  415. data/shoes/ruby/lib/rexml/dtd/entitydecl.rb +56 -0
  416. data/shoes/ruby/lib/rexml/dtd/notationdecl.rb +39 -0
  417. data/shoes/ruby/lib/rexml/element.rb +1246 -0
  418. data/shoes/ruby/lib/rexml/encoding.rb +71 -0
  419. data/shoes/ruby/lib/rexml/encodings/CP-1252.rb +103 -0
  420. data/shoes/ruby/lib/rexml/encodings/EUC-JP.rb +35 -0
  421. data/shoes/ruby/lib/rexml/encodings/ICONV.rb +22 -0
  422. data/shoes/ruby/lib/rexml/encodings/ISO-8859-1.rb +7 -0
  423. data/shoes/ruby/lib/rexml/encodings/ISO-8859-15.rb +72 -0
  424. data/shoes/ruby/lib/rexml/encodings/SHIFT-JIS.rb +37 -0
  425. data/shoes/ruby/lib/rexml/encodings/SHIFT_JIS.rb +1 -0
  426. data/shoes/ruby/lib/rexml/encodings/UNILE.rb +34 -0
  427. data/shoes/ruby/lib/rexml/encodings/US-ASCII.rb +30 -0
  428. data/shoes/ruby/lib/rexml/encodings/UTF-16.rb +35 -0
  429. data/shoes/ruby/lib/rexml/encodings/UTF-8.rb +18 -0
  430. data/shoes/ruby/lib/rexml/entity.rb +166 -0
  431. data/shoes/ruby/lib/rexml/formatters/default.rb +109 -0
  432. data/shoes/ruby/lib/rexml/formatters/pretty.rb +139 -0
  433. data/shoes/ruby/lib/rexml/formatters/transitive.rb +58 -0
  434. data/shoes/ruby/lib/rexml/functions.rb +388 -0
  435. data/shoes/ruby/lib/rexml/instruction.rb +70 -0
  436. data/shoes/ruby/lib/rexml/light/node.rb +196 -0
  437. data/shoes/ruby/lib/rexml/namespace.rb +47 -0
  438. data/shoes/ruby/lib/rexml/node.rb +75 -0
  439. data/shoes/ruby/lib/rexml/output.rb +24 -0
  440. data/shoes/ruby/lib/rexml/parent.rb +166 -0
  441. data/shoes/ruby/lib/rexml/parseexception.rb +51 -0
  442. data/shoes/ruby/lib/rexml/parsers/baseparser.rb +530 -0
  443. data/shoes/ruby/lib/rexml/parsers/lightparser.rb +58 -0
  444. data/shoes/ruby/lib/rexml/parsers/pullparser.rb +196 -0
  445. data/shoes/ruby/lib/rexml/parsers/sax2parser.rb +247 -0
  446. data/shoes/ruby/lib/rexml/parsers/streamparser.rb +46 -0
  447. data/shoes/ruby/lib/rexml/parsers/treeparser.rb +100 -0
  448. data/shoes/ruby/lib/rexml/parsers/ultralightparser.rb +56 -0
  449. data/shoes/ruby/lib/rexml/parsers/xpathparser.rb +698 -0
  450. data/shoes/ruby/lib/rexml/quickpath.rb +263 -0
  451. data/shoes/ruby/lib/rexml/rexml.rb +31 -0
  452. data/shoes/ruby/lib/rexml/sax2listener.rb +97 -0
  453. data/shoes/ruby/lib/rexml/source.rb +258 -0
  454. data/shoes/ruby/lib/rexml/streamlistener.rb +92 -0
  455. data/shoes/ruby/lib/rexml/syncenumerator.rb +32 -0
  456. data/shoes/ruby/lib/rexml/text.rb +404 -0
  457. data/shoes/ruby/lib/rexml/undefinednamespaceexception.rb +8 -0
  458. data/shoes/ruby/lib/rexml/validation/relaxng.rb +559 -0
  459. data/shoes/ruby/lib/rexml/validation/validation.rb +155 -0
  460. data/shoes/ruby/lib/rexml/validation/validationexception.rb +9 -0
  461. data/shoes/ruby/lib/rexml/xmldecl.rb +119 -0
  462. data/shoes/ruby/lib/rexml/xmltokens.rb +18 -0
  463. data/shoes/ruby/lib/rexml/xpath.rb +77 -0
  464. data/shoes/ruby/lib/rexml/xpath_parser.rb +792 -0
  465. data/shoes/ruby/lib/rinda/rinda.rb +283 -0
  466. data/shoes/ruby/lib/rinda/ring.rb +271 -0
  467. data/shoes/ruby/lib/rinda/tuplespace.rb +642 -0
  468. data/shoes/ruby/lib/ripper/core.rb +70 -0
  469. data/shoes/ruby/lib/ripper/filter.rb +70 -0
  470. data/shoes/ruby/lib/ripper/lexer.rb +179 -0
  471. data/shoes/ruby/lib/ripper/sexp.rb +99 -0
  472. data/shoes/ruby/lib/ripper.rb +4 -0
  473. data/shoes/ruby/lib/rss/0.9.rb +427 -0
  474. data/shoes/ruby/lib/rss/1.0.rb +452 -0
  475. data/shoes/ruby/lib/rss/2.0.rb +111 -0
  476. data/shoes/ruby/lib/rss/atom.rb +748 -0
  477. data/shoes/ruby/lib/rss/content/1.0.rb +10 -0
  478. data/shoes/ruby/lib/rss/content/2.0.rb +12 -0
  479. data/shoes/ruby/lib/rss/content.rb +31 -0
  480. data/shoes/ruby/lib/rss/converter.rb +170 -0
  481. data/shoes/ruby/lib/rss/dublincore/1.0.rb +13 -0
  482. data/shoes/ruby/lib/rss/dublincore/2.0.rb +13 -0
  483. data/shoes/ruby/lib/rss/dublincore/atom.rb +17 -0
  484. data/shoes/ruby/lib/rss/dublincore.rb +161 -0
  485. data/shoes/ruby/lib/rss/image.rb +193 -0
  486. data/shoes/ruby/lib/rss/itunes.rb +410 -0
  487. data/shoes/ruby/lib/rss/maker/0.9.rb +467 -0
  488. data/shoes/ruby/lib/rss/maker/1.0.rb +434 -0
  489. data/shoes/ruby/lib/rss/maker/2.0.rb +223 -0
  490. data/shoes/ruby/lib/rss/maker/atom.rb +172 -0
  491. data/shoes/ruby/lib/rss/maker/base.rb +880 -0
  492. data/shoes/ruby/lib/rss/maker/content.rb +21 -0
  493. data/shoes/ruby/lib/rss/maker/dublincore.rb +124 -0
  494. data/shoes/ruby/lib/rss/maker/entry.rb +163 -0
  495. data/shoes/ruby/lib/rss/maker/feed.rb +430 -0
  496. data/shoes/ruby/lib/rss/maker/image.rb +111 -0
  497. data/shoes/ruby/lib/rss/maker/itunes.rb +242 -0
  498. data/shoes/ruby/lib/rss/maker/slash.rb +33 -0
  499. data/shoes/ruby/lib/rss/maker/syndication.rb +18 -0
  500. data/shoes/ruby/lib/rss/maker/taxonomy.rb +118 -0
  501. data/shoes/ruby/lib/rss/maker/trackback.rb +61 -0
  502. data/shoes/ruby/lib/rss/maker.rb +44 -0
  503. data/shoes/ruby/lib/rss/parser.rb +568 -0
  504. data/shoes/ruby/lib/rss/rexmlparser.rb +54 -0
  505. data/shoes/ruby/lib/rss/rss.rb +1313 -0
  506. data/shoes/ruby/lib/rss/slash.rb +49 -0
  507. data/shoes/ruby/lib/rss/syndication.rb +67 -0
  508. data/shoes/ruby/lib/rss/taxonomy.rb +145 -0
  509. data/shoes/ruby/lib/rss/trackback.rb +288 -0
  510. data/shoes/ruby/lib/rss/utils.rb +111 -0
  511. data/shoes/ruby/lib/rss/xml-stylesheet.rb +105 -0
  512. data/shoes/ruby/lib/rss/xml.rb +71 -0
  513. data/shoes/ruby/lib/rss/xmlparser.rb +93 -0
  514. data/shoes/ruby/lib/rss/xmlscanner.rb +121 -0
  515. data/shoes/ruby/lib/rss.rb +19 -0
  516. data/shoes/ruby/lib/rubygems/builder.rb +88 -0
  517. data/shoes/ruby/lib/rubygems/command.rb +406 -0
  518. data/shoes/ruby/lib/rubygems/command_manager.rb +146 -0
  519. data/shoes/ruby/lib/rubygems/commands/build_command.rb +53 -0
  520. data/shoes/ruby/lib/rubygems/commands/cert_command.rb +86 -0
  521. data/shoes/ruby/lib/rubygems/commands/check_command.rb +75 -0
  522. data/shoes/ruby/lib/rubygems/commands/cleanup_command.rb +91 -0
  523. data/shoes/ruby/lib/rubygems/commands/contents_command.rb +74 -0
  524. data/shoes/ruby/lib/rubygems/commands/dependency_command.rb +188 -0
  525. data/shoes/ruby/lib/rubygems/commands/environment_command.rb +128 -0
  526. data/shoes/ruby/lib/rubygems/commands/fetch_command.rb +62 -0
  527. data/shoes/ruby/lib/rubygems/commands/generate_index_command.rb +57 -0
  528. data/shoes/ruby/lib/rubygems/commands/help_command.rb +172 -0
  529. data/shoes/ruby/lib/rubygems/commands/install_command.rb +148 -0
  530. data/shoes/ruby/lib/rubygems/commands/list_command.rb +35 -0
  531. data/shoes/ruby/lib/rubygems/commands/lock_command.rb +110 -0
  532. data/shoes/ruby/lib/rubygems/commands/mirror_command.rb +111 -0
  533. data/shoes/ruby/lib/rubygems/commands/outdated_command.rb +33 -0
  534. data/shoes/ruby/lib/rubygems/commands/pristine_command.rb +93 -0
  535. data/shoes/ruby/lib/rubygems/commands/query_command.rb +233 -0
  536. data/shoes/ruby/lib/rubygems/commands/rdoc_command.rb +82 -0
  537. data/shoes/ruby/lib/rubygems/commands/search_command.rb +37 -0
  538. data/shoes/ruby/lib/rubygems/commands/server_command.rb +48 -0
  539. data/shoes/ruby/lib/rubygems/commands/sources_command.rb +152 -0
  540. data/shoes/ruby/lib/rubygems/commands/specification_command.rb +77 -0
  541. data/shoes/ruby/lib/rubygems/commands/stale_command.rb +27 -0
  542. data/shoes/ruby/lib/rubygems/commands/uninstall_command.rb +73 -0
  543. data/shoes/ruby/lib/rubygems/commands/unpack_command.rb +95 -0
  544. data/shoes/ruby/lib/rubygems/commands/update_command.rb +181 -0
  545. data/shoes/ruby/lib/rubygems/commands/which_command.rb +87 -0
  546. data/shoes/ruby/lib/rubygems/config_file.rb +266 -0
  547. data/shoes/ruby/lib/rubygems/custom_require.rb +46 -0
  548. data/shoes/ruby/lib/rubygems/defaults.rb +89 -0
  549. data/shoes/ruby/lib/rubygems/dependency.rb +119 -0
  550. data/shoes/ruby/lib/rubygems/dependency_installer.rb +258 -0
  551. data/shoes/ruby/lib/rubygems/dependency_list.rb +165 -0
  552. data/shoes/ruby/lib/rubygems/digest/digest_adapter.rb +40 -0
  553. data/shoes/ruby/lib/rubygems/digest/md5.rb +23 -0
  554. data/shoes/ruby/lib/rubygems/digest/sha1.rb +17 -0
  555. data/shoes/ruby/lib/rubygems/digest/sha2.rb +17 -0
  556. data/shoes/ruby/lib/rubygems/doc_manager.rb +214 -0
  557. data/shoes/ruby/lib/rubygems/exceptions.rb +84 -0
  558. data/shoes/ruby/lib/rubygems/ext/builder.rb +56 -0
  559. data/shoes/ruby/lib/rubygems/ext/configure_builder.rb +24 -0
  560. data/shoes/ruby/lib/rubygems/ext/ext_conf_builder.rb +23 -0
  561. data/shoes/ruby/lib/rubygems/ext/rake_builder.rb +27 -0
  562. data/shoes/ruby/lib/rubygems/ext.rb +18 -0
  563. data/shoes/ruby/lib/rubygems/format.rb +87 -0
  564. data/shoes/ruby/lib/rubygems/gem_openssl.rb +83 -0
  565. data/shoes/ruby/lib/rubygems/gem_path_searcher.rb +100 -0
  566. data/shoes/ruby/lib/rubygems/gem_runner.rb +58 -0
  567. data/shoes/ruby/lib/rubygems/indexer/abstract_index_builder.rb +88 -0
  568. data/shoes/ruby/lib/rubygems/indexer/latest_index_builder.rb +35 -0
  569. data/shoes/ruby/lib/rubygems/indexer/marshal_index_builder.rb +17 -0
  570. data/shoes/ruby/lib/rubygems/indexer/master_index_builder.rb +54 -0
  571. data/shoes/ruby/lib/rubygems/indexer/quick_index_builder.rb +50 -0
  572. data/shoes/ruby/lib/rubygems/indexer.rb +370 -0
  573. data/shoes/ruby/lib/rubygems/install_update_options.rb +113 -0
  574. data/shoes/ruby/lib/rubygems/installer.rb +578 -0
  575. data/shoes/ruby/lib/rubygems/local_remote_options.rb +134 -0
  576. data/shoes/ruby/lib/rubygems/old_format.rb +148 -0
  577. data/shoes/ruby/lib/rubygems/package/f_sync_dir.rb +24 -0
  578. data/shoes/ruby/lib/rubygems/package/tar_header.rb +245 -0
  579. data/shoes/ruby/lib/rubygems/package/tar_input.rb +219 -0
  580. data/shoes/ruby/lib/rubygems/package/tar_output.rb +143 -0
  581. data/shoes/ruby/lib/rubygems/package/tar_reader/entry.rb +99 -0
  582. data/shoes/ruby/lib/rubygems/package/tar_reader.rb +86 -0
  583. data/shoes/ruby/lib/rubygems/package/tar_writer.rb +180 -0
  584. data/shoes/ruby/lib/rubygems/package.rb +95 -0
  585. data/shoes/ruby/lib/rubygems/platform.rb +178 -0
  586. data/shoes/ruby/lib/rubygems/remote_fetcher.rb +344 -0
  587. data/shoes/ruby/lib/rubygems/require_paths_builder.rb +15 -0
  588. data/shoes/ruby/lib/rubygems/requirement.rb +163 -0
  589. data/shoes/ruby/lib/rubygems/rubygems_version.rb +6 -0
  590. data/shoes/ruby/lib/rubygems/security.rb +786 -0
  591. data/shoes/ruby/lib/rubygems/server.rb +629 -0
  592. data/shoes/ruby/lib/rubygems/source_index.rb +559 -0
  593. data/shoes/ruby/lib/rubygems/source_info_cache.rb +393 -0
  594. data/shoes/ruby/lib/rubygems/source_info_cache_entry.rb +56 -0
  595. data/shoes/ruby/lib/rubygems/spec_fetcher.rb +249 -0
  596. data/shoes/ruby/lib/rubygems/specification.rb +1262 -0
  597. data/shoes/ruby/lib/rubygems/test_utilities.rb +131 -0
  598. data/shoes/ruby/lib/rubygems/timer.rb +25 -0
  599. data/shoes/ruby/lib/rubygems/uninstaller.rb +242 -0
  600. data/shoes/ruby/lib/rubygems/user_interaction.rb +360 -0
  601. data/shoes/ruby/lib/rubygems/validator.rb +208 -0
  602. data/shoes/ruby/lib/rubygems/version.rb +167 -0
  603. data/shoes/ruby/lib/rubygems/version_option.rb +48 -0
  604. data/shoes/ruby/lib/rubygems.rb +888 -0
  605. data/shoes/ruby/lib/scanf.rb +703 -0
  606. data/shoes/ruby/lib/securerandom.rb +182 -0
  607. data/shoes/ruby/lib/set.rb +1274 -0
  608. data/shoes/ruby/lib/shell/builtin-command.rb +160 -0
  609. data/shoes/ruby/lib/shell/command-processor.rb +593 -0
  610. data/shoes/ruby/lib/shell/error.rb +25 -0
  611. data/shoes/ruby/lib/shell/filter.rb +109 -0
  612. data/shoes/ruby/lib/shell/process-controller.rb +319 -0
  613. data/shoes/ruby/lib/shell/system-command.rb +159 -0
  614. data/shoes/ruby/lib/shell/version.rb +15 -0
  615. data/shoes/ruby/lib/shell.rb +300 -0
  616. data/shoes/ruby/lib/shellwords.rb +156 -0
  617. data/shoes/ruby/lib/singleton.rb +313 -0
  618. data/shoes/ruby/lib/sync.rb +307 -0
  619. data/shoes/ruby/lib/tempfile.rb +218 -0
  620. data/shoes/ruby/lib/test/unit/assertions.rb +122 -0
  621. data/shoes/ruby/lib/test/unit/testcase.rb +12 -0
  622. data/shoes/ruby/lib/test/unit.rb +66 -0
  623. data/shoes/ruby/lib/thread.rb +367 -0
  624. data/shoes/ruby/lib/thwait.rb +168 -0
  625. data/shoes/ruby/lib/time.rb +869 -0
  626. data/shoes/ruby/lib/timeout.rb +108 -0
  627. data/shoes/ruby/lib/tmpdir.rb +138 -0
  628. data/shoes/ruby/lib/tracer.rb +166 -0
  629. data/shoes/ruby/lib/tsort.rb +290 -0
  630. data/shoes/ruby/lib/ubygems.rb +10 -0
  631. data/shoes/ruby/lib/un.rb +304 -0
  632. data/shoes/ruby/lib/uri/common.rb +727 -0
  633. data/shoes/ruby/lib/uri/ftp.rb +198 -0
  634. data/shoes/ruby/lib/uri/generic.rb +1128 -0
  635. data/shoes/ruby/lib/uri/http.rb +100 -0
  636. data/shoes/ruby/lib/uri/https.rb +20 -0
  637. data/shoes/ruby/lib/uri/ldap.rb +190 -0
  638. data/shoes/ruby/lib/uri/ldaps.rb +12 -0
  639. data/shoes/ruby/lib/uri/mailto.rb +266 -0
  640. data/shoes/ruby/lib/uri.rb +29 -0
  641. data/shoes/ruby/lib/weakref.rb +80 -0
  642. data/shoes/ruby/lib/webrick/accesslog.rb +75 -0
  643. data/shoes/ruby/lib/webrick/cgi.rb +260 -0
  644. data/shoes/ruby/lib/webrick/compat.rb +15 -0
  645. data/shoes/ruby/lib/webrick/config.rb +100 -0
  646. data/shoes/ruby/lib/webrick/cookie.rb +110 -0
  647. data/shoes/ruby/lib/webrick/htmlutils.rb +25 -0
  648. data/shoes/ruby/lib/webrick/httpauth/authenticator.rb +79 -0
  649. data/shoes/ruby/lib/webrick/httpauth/basicauth.rb +65 -0
  650. data/shoes/ruby/lib/webrick/httpauth/digestauth.rb +344 -0
  651. data/shoes/ruby/lib/webrick/httpauth/htdigest.rb +91 -0
  652. data/shoes/ruby/lib/webrick/httpauth/htgroup.rb +61 -0
  653. data/shoes/ruby/lib/webrick/httpauth/htpasswd.rb +83 -0
  654. data/shoes/ruby/lib/webrick/httpauth/userdb.rb +29 -0
  655. data/shoes/ruby/lib/webrick/httpauth.rb +45 -0
  656. data/shoes/ruby/lib/webrick/httpproxy.rb +288 -0
  657. data/shoes/ruby/lib/webrick/httprequest.rb +402 -0
  658. data/shoes/ruby/lib/webrick/httpresponse.rb +326 -0
  659. data/shoes/ruby/lib/webrick/https.rb +63 -0
  660. data/shoes/ruby/lib/webrick/httpserver.rb +217 -0
  661. data/shoes/ruby/lib/webrick/httpservlet/abstract.rb +70 -0
  662. data/shoes/ruby/lib/webrick/httpservlet/cgi_runner.rb +47 -0
  663. data/shoes/ruby/lib/webrick/httpservlet/cgihandler.rb +110 -0
  664. data/shoes/ruby/lib/webrick/httpservlet/erbhandler.rb +54 -0
  665. data/shoes/ruby/lib/webrick/httpservlet/filehandler.rb +435 -0
  666. data/shoes/ruby/lib/webrick/httpservlet/prochandler.rb +33 -0
  667. data/shoes/ruby/lib/webrick/httpservlet.rb +22 -0
  668. data/shoes/ruby/lib/webrick/httpstatus.rb +132 -0
  669. data/shoes/ruby/lib/webrick/httputils.rb +392 -0
  670. data/shoes/ruby/lib/webrick/httpversion.rb +49 -0
  671. data/shoes/ruby/lib/webrick/log.rb +88 -0
  672. data/shoes/ruby/lib/webrick/server.rb +210 -0
  673. data/shoes/ruby/lib/webrick/ssl.rb +126 -0
  674. data/shoes/ruby/lib/webrick/utils.rb +175 -0
  675. data/shoes/ruby/lib/webrick/version.rb +13 -0
  676. data/shoes/ruby/lib/webrick.rb +29 -0
  677. data/shoes/ruby/lib/win32/registry.rb +832 -0
  678. data/shoes/ruby/lib/win32/resolv.rb +370 -0
  679. data/shoes/ruby/lib/win32/sspi.rb +330 -0
  680. data/shoes/ruby/lib/win32ole/property.rb +16 -0
  681. data/shoes/ruby/lib/xmlrpc/base64.rb +81 -0
  682. data/shoes/ruby/lib/xmlrpc/client.rb +625 -0
  683. data/shoes/ruby/lib/xmlrpc/config.rb +40 -0
  684. data/shoes/ruby/lib/xmlrpc/create.rb +290 -0
  685. data/shoes/ruby/lib/xmlrpc/datetime.rb +142 -0
  686. data/shoes/ruby/lib/xmlrpc/httpserver.rb +178 -0
  687. data/shoes/ruby/lib/xmlrpc/marshal.rb +76 -0
  688. data/shoes/ruby/lib/xmlrpc/parser.rb +813 -0
  689. data/shoes/ruby/lib/xmlrpc/server.rb +778 -0
  690. data/shoes/ruby/lib/xmlrpc/utils.rb +165 -0
  691. data/shoes/ruby/lib/yaml/baseemitter.rb +242 -0
  692. data/shoes/ruby/lib/yaml/basenode.rb +216 -0
  693. data/shoes/ruby/lib/yaml/constants.rb +45 -0
  694. data/shoes/ruby/lib/yaml/dbm.rb +111 -0
  695. data/shoes/ruby/lib/yaml/encoding.rb +33 -0
  696. data/shoes/ruby/lib/yaml/error.rb +34 -0
  697. data/shoes/ruby/lib/yaml/loader.rb +14 -0
  698. data/shoes/ruby/lib/yaml/rubytypes.rb +446 -0
  699. data/shoes/ruby/lib/yaml/store.rb +43 -0
  700. data/shoes/ruby/lib/yaml/stream.rb +40 -0
  701. data/shoes/ruby/lib/yaml/stringio.rb +83 -0
  702. data/shoes/ruby/lib/yaml/syck.rb +19 -0
  703. data/shoes/ruby/lib/yaml/tag.rb +91 -0
  704. data/shoes/ruby/lib/yaml/types.rb +192 -0
  705. data/shoes/ruby/lib/yaml/yamlnode.rb +54 -0
  706. data/shoes/ruby/lib/yaml/ypath.rb +52 -0
  707. data/shoes/ruby/lib/yaml.rb +440 -0
  708. data/shoes/samples/class-book.rb +43 -0
  709. data/shoes/samples/class-book.yaml +387 -0
  710. data/shoes/samples/expert-definr.rb +23 -0
  711. data/shoes/samples/expert-funnies.rb +51 -0
  712. data/shoes/samples/expert-irb.rb +112 -0
  713. data/shoes/samples/expert-minesweeper.rb +267 -0
  714. data/shoes/samples/expert-othello.rb +319 -0
  715. data/shoes/samples/expert-pong.rb +62 -0
  716. data/shoes/samples/expert-tankspank.rb +385 -0
  717. data/shoes/samples/good-arc.rb +37 -0
  718. data/shoes/samples/good-clock.rb +51 -0
  719. data/shoes/samples/good-follow.rb +26 -0
  720. data/shoes/samples/good-reminder.rb +174 -0
  721. data/shoes/samples/good-vjot.rb +56 -0
  722. data/shoes/samples/simple-accordion.rb +75 -0
  723. data/shoes/samples/simple-anim-shapes.rb +17 -0
  724. data/shoes/samples/simple-anim-text.rb +13 -0
  725. data/shoes/samples/simple-arc.rb +23 -0
  726. data/shoes/samples/simple-bounce.rb +24 -0
  727. data/shoes/samples/simple-calc.rb +70 -0
  728. data/shoes/samples/simple-control-sizes.rb +24 -0
  729. data/shoes/samples/simple-curve.rb +26 -0
  730. data/shoes/samples/simple-dialogs.rb +29 -0
  731. data/shoes/samples/simple-downloader.rb +27 -0
  732. data/shoes/samples/simple-draw.rb +13 -0
  733. data/shoes/samples/simple-editor.rb +28 -0
  734. data/shoes/samples/simple-form.rb +28 -0
  735. data/shoes/samples/simple-form.shy +0 -0
  736. data/shoes/samples/simple-mask.rb +21 -0
  737. data/shoes/samples/simple-menu.rb +31 -0
  738. data/shoes/samples/simple-menu1.rb +35 -0
  739. data/shoes/samples/simple-rubygems.rb +29 -0
  740. data/shoes/samples/simple-slide.rb +45 -0
  741. data/shoes/samples/simple-sphere.rb +28 -0
  742. data/shoes/samples/simple-timer.rb +13 -0
  743. data/shoes/samples/simple-video.rb +13 -0
  744. data/shoes/shoes +21 -0
  745. data/shoes/shoes.exe +0 -0
  746. data/shoes/shoes.exe.manifest +17 -0
  747. data/shoes/sqlite3.dll +0 -0
  748. data/shoes/static/Shoes.icns +0 -0
  749. data/shoes/static/Thumbs.db +0 -0
  750. data/shoes/static/app-icon.png +0 -0
  751. data/shoes/static/avatar.png +0 -0
  752. data/shoes/static/code_highlighter.js +188 -0
  753. data/shoes/static/code_highlighter_ruby.js +26 -0
  754. data/shoes/static/icon-debug.png +0 -0
  755. data/shoes/static/icon-error.png +0 -0
  756. data/shoes/static/icon-info.png +0 -0
  757. data/shoes/static/icon-warn.png +0 -0
  758. data/shoes/static/listbox_button1.png +0 -0
  759. data/shoes/static/listbox_button2.png +0 -0
  760. data/shoes/static/man-app.png +0 -0
  761. data/shoes/static/man-builds.png +0 -0
  762. data/shoes/static/man-editor-notepad.png +0 -0
  763. data/shoes/static/man-editor-osx.png +0 -0
  764. data/shoes/static/man-ele-background.png +0 -0
  765. data/shoes/static/man-ele-border.png +0 -0
  766. data/shoes/static/man-ele-button.png +0 -0
  767. data/shoes/static/man-ele-check.png +0 -0
  768. data/shoes/static/man-ele-editbox.png +0 -0
  769. data/shoes/static/man-ele-editline.png +0 -0
  770. data/shoes/static/man-ele-image.png +0 -0
  771. data/shoes/static/man-ele-listbox.png +0 -0
  772. data/shoes/static/man-ele-progress.png +0 -0
  773. data/shoes/static/man-ele-radio.png +0 -0
  774. data/shoes/static/man-ele-shape.png +0 -0
  775. data/shoes/static/man-ele-textblock.png +0 -0
  776. data/shoes/static/man-ele-video.png +0 -0
  777. data/shoes/static/man-intro-dmg.png +0 -0
  778. data/shoes/static/man-intro-exe.png +0 -0
  779. data/shoes/static/man-look-tiger.png +0 -0
  780. data/shoes/static/man-look-ubuntu.png +0 -0
  781. data/shoes/static/man-look-vista.png +0 -0
  782. data/shoes/static/man-run-osx.png +0 -0
  783. data/shoes/static/man-run-vista.png +0 -0
  784. data/shoes/static/man-run-xp.png +0 -0
  785. data/shoes/static/man-shot1.png +0 -0
  786. data/shoes/static/manual-en.txt +2783 -0
  787. data/shoes/static/manual-ja.txt +2780 -0
  788. data/shoes/static/manual.css +167 -0
  789. data/shoes/static/menu-corner1.png +0 -0
  790. data/shoes/static/menu-corner2.png +0 -0
  791. data/shoes/static/menu-gray.png +0 -0
  792. data/shoes/static/menu-left.png +0 -0
  793. data/shoes/static/menu-right.png +0 -0
  794. data/shoes/static/menu-top.png +0 -0
  795. data/shoes/static/shoes-dmg.jpg +0 -0
  796. data/shoes/static/shoes-icon-blue.png +0 -0
  797. data/shoes/static/shoes-icon.png +0 -0
  798. data/shoes/static/shoes-manual-apps.gif +0 -0
  799. data/shoes/static/stripe.png +0 -0
  800. data/shoes/static/stubs/blank.exe +0 -0
  801. data/shoes/static/stubs/blank.hfz +0 -0
  802. data/shoes/static/stubs/blank.run +375 -0
  803. data/shoes/static/stubs/cocoa-install +0 -0
  804. data/shoes/static/stubs/sh-install +48 -0
  805. data/shoes/static/tutor-back.png +0 -0
  806. data/shoes/zlib.dll +0 -0
  807. data/shoes/zlib1.dll +0 -0
  808. metadata +887 -0
@@ -0,0 +1,1834 @@
1
+ #
2
+ # date.rb - date and time library
3
+ #
4
+ # Author: Tadayoshi Funaba 1998-2008
5
+ #
6
+ # Documentation: William Webber <william@williamwebber.com>
7
+ #
8
+ #--
9
+ # $Id: date.rb,v 2.37 2008-01-17 20:16:31+09 tadf Exp $
10
+ #++
11
+ #
12
+ # == Overview
13
+ #
14
+ # This file provides two classes for working with
15
+ # dates and times.
16
+ #
17
+ # The first class, Date, represents dates.
18
+ # It works with years, months, weeks, and days.
19
+ # See the Date class documentation for more details.
20
+ #
21
+ # The second, DateTime, extends Date to include hours,
22
+ # minutes, seconds, and fractions of a second. It
23
+ # provides basic support for time zones. See the
24
+ # DateTime class documentation for more details.
25
+ #
26
+ # === Ways of calculating the date.
27
+ #
28
+ # In common usage, the date is reckoned in years since or
29
+ # before the Common Era (CE/BCE, also known as AD/BC), then
30
+ # as a month and day-of-the-month within the current year.
31
+ # This is known as the *Civil* *Date*, and abbreviated
32
+ # as +civil+ in the Date class.
33
+ #
34
+ # Instead of year, month-of-the-year, and day-of-the-month,
35
+ # the date can also be reckoned in terms of year and
36
+ # day-of-the-year. This is known as the *Ordinal* *Date*,
37
+ # and is abbreviated as +ordinal+ in the Date class. (Note
38
+ # that referring to this as the Julian date is incorrect.)
39
+ #
40
+ # The date can also be reckoned in terms of year, week-of-the-year,
41
+ # and day-of-the-week. This is known as the *Commercial*
42
+ # *Date*, and is abbreviated as +commercial+ in the
43
+ # Date class. The commercial week runs Monday (day-of-the-week
44
+ # 1) to Sunday (day-of-the-week 7), in contrast to the civil
45
+ # week which runs Sunday (day-of-the-week 0) to Saturday
46
+ # (day-of-the-week 6). The first week of the commercial year
47
+ # starts on the Monday on or before January 1, and the commercial
48
+ # year itself starts on this Monday, not January 1.
49
+ #
50
+ # For scientific purposes, it is convenient to refer to a date
51
+ # simply as a day count, counting from an arbitrary initial
52
+ # day. The date first chosen for this was January 1, 4713 BCE.
53
+ # A count of days from this date is the *Julian* *Day* *Number*
54
+ # or *Julian* *Date*, which is abbreviated as +jd+ in the
55
+ # Date class. This is in local time, and counts from midnight
56
+ # on the initial day. The stricter usage is in UTC, and counts
57
+ # from midday on the initial day. This is referred to in the
58
+ # Date class as the *Astronomical* *Julian* *Day* *Number*, and
59
+ # abbreviated as +ajd+. In the Date class, the Astronomical
60
+ # Julian Day Number includes fractional days.
61
+ #
62
+ # Another absolute day count is the *Modified* *Julian* *Day*
63
+ # *Number*, which takes November 17, 1858 as its initial day.
64
+ # This is abbreviated as +mjd+ in the Date class. There
65
+ # is also an *Astronomical* *Modified* *Julian* *Day* *Number*,
66
+ # which is in UTC and includes fractional days. This is
67
+ # abbreviated as +amjd+ in the Date class. Like the Modified
68
+ # Julian Day Number (and unlike the Astronomical Julian
69
+ # Day Number), it counts from midnight.
70
+ #
71
+ # Alternative calendars such as the Chinese Lunar Calendar,
72
+ # the Islamic Calendar, or the French Revolutionary Calendar
73
+ # are not supported by the Date class; nor are calendars that
74
+ # are based on an Era different from the Common Era, such as
75
+ # the Japanese Imperial Calendar or the Republic of China
76
+ # Calendar.
77
+ #
78
+ # === Calendar Reform
79
+ #
80
+ # The standard civil year is 365 days long. However, the
81
+ # solar year is fractionally longer than this. To account
82
+ # for this, a *leap* *year* is occasionally inserted. This
83
+ # is a year with 366 days, the extra day falling on February 29.
84
+ # In the early days of the civil calendar, every fourth
85
+ # year without exception was a leap year. This way of
86
+ # reckoning leap years is the *Julian* *Calendar*.
87
+ #
88
+ # However, the solar year is marginally shorter than 365 1/4
89
+ # days, and so the *Julian* *Calendar* gradually ran slow
90
+ # over the centuries. To correct this, every 100th year
91
+ # (but not every 400th year) was excluded as a leap year.
92
+ # This way of reckoning leap years, which we use today, is
93
+ # the *Gregorian* *Calendar*.
94
+ #
95
+ # The Gregorian Calendar was introduced at different times
96
+ # in different regions. The day on which it was introduced
97
+ # for a particular region is the *Day* *of* *Calendar*
98
+ # *Reform* for that region. This is abbreviated as +sg+
99
+ # (for Start of Gregorian calendar) in the Date class.
100
+ #
101
+ # Two such days are of particular
102
+ # significance. The first is October 15, 1582, which was
103
+ # the Day of Calendar Reform for Italy and most Catholic
104
+ # countries. The second is September 14, 1752, which was
105
+ # the Day of Calendar Reform for England and its colonies
106
+ # (including what is now the United States). These two
107
+ # dates are available as the constants Date::ITALY and
108
+ # Date::ENGLAND, respectively. (By comparison, Germany and
109
+ # Holland, less Catholic than Italy but less stubborn than
110
+ # England, changed over in 1698; Sweden in 1753; Russia not
111
+ # till 1918, after the Revolution; and Greece in 1923. Many
112
+ # Orthodox churches still use the Julian Calendar. A complete
113
+ # list of Days of Calendar Reform can be found at
114
+ # http://www.polysyllabic.com/GregConv.html.)
115
+ #
116
+ # Switching from the Julian to the Gregorian calendar
117
+ # involved skipping a number of days to make up for the
118
+ # accumulated lag, and the later the switch was (or is)
119
+ # done, the more days need to be skipped. So in 1582 in Italy,
120
+ # 4th October was followed by 15th October, skipping 10 days; in 1752
121
+ # in England, 2nd September was followed by 14th September, skipping
122
+ # 11 days; and if I decided to switch from Julian to Gregorian
123
+ # Calendar this midnight, I would go from 27th July 2003 (Julian)
124
+ # today to 10th August 2003 (Gregorian) tomorrow, skipping
125
+ # 13 days. The Date class is aware of this gap, and a supposed
126
+ # date that would fall in the middle of it is regarded as invalid.
127
+ #
128
+ # The Day of Calendar Reform is relevant to all date representations
129
+ # involving years. It is not relevant to the Julian Day Numbers,
130
+ # except for converting between them and year-based representations.
131
+ #
132
+ # In the Date and DateTime classes, the Day of Calendar Reform or
133
+ # +sg+ can be specified a number of ways. First, it can be as
134
+ # the Julian Day Number of the Day of Calendar Reform. Second,
135
+ # it can be using the constants Date::ITALY or Date::ENGLAND; these
136
+ # are in fact the Julian Day Numbers of the Day of Calendar Reform
137
+ # of the respective regions. Third, it can be as the constant
138
+ # Date::JULIAN, which means to always use the Julian Calendar.
139
+ # Finally, it can be as the constant Date::GREGORIAN, which means
140
+ # to always use the Gregorian Calendar.
141
+ #
142
+ # Note: in the Julian Calendar, New Years Day was March 25. The
143
+ # Date class does not follow this convention.
144
+ #
145
+ # === Time Zones
146
+ #
147
+ # DateTime objects support a simple representation
148
+ # of time zones. Time zones are represented as an offset
149
+ # from UTC, as a fraction of a day. This offset is the
150
+ # how much local time is later (or earlier) than UTC.
151
+ # UTC offset 0 is centred on England (also known as GMT).
152
+ # As you travel east, the offset increases until you
153
+ # reach the dateline in the middle of the Pacific Ocean;
154
+ # as you travel west, the offset decreases. This offset
155
+ # is abbreviated as +of+ in the Date class.
156
+ #
157
+ # This simple representation of time zones does not take
158
+ # into account the common practice of Daylight Savings
159
+ # Time or Summer Time.
160
+ #
161
+ # Most DateTime methods return the date and the
162
+ # time in local time. The two exceptions are
163
+ # #ajd() and #amjd(), which return the date and time
164
+ # in UTC time, including fractional days.
165
+ #
166
+ # The Date class does not support time zone offsets, in that
167
+ # there is no way to create a Date object with a time zone.
168
+ # However, methods of the Date class when used by a
169
+ # DateTime instance will use the time zone offset of this
170
+ # instance.
171
+ #
172
+ # == Examples of use
173
+ #
174
+ # === Print out the date of every Sunday between two dates.
175
+ #
176
+ # def print_sundays(d1, d2)
177
+ # d1 +=1 while (d1.wday != 0)
178
+ # d1.step(d2, 7) do |date|
179
+ # puts "#{Date::MONTHNAMES[date.mon]} #{date.day}"
180
+ # end
181
+ # end
182
+ #
183
+ # print_sundays(Date::civil(2003, 4, 8), Date::civil(2003, 5, 23))
184
+ #
185
+ # === Calculate how many seconds to go till midnight on New Year's Day.
186
+ #
187
+ # def secs_to_new_year(now = DateTime::now())
188
+ # new_year = DateTime.new(now.year + 1, 1, 1)
189
+ # dif = new_year - now
190
+ # hours, mins, secs, ignore_fractions = Date::day_fraction_to_time(dif)
191
+ # return hours * 60 * 60 + mins * 60 + secs
192
+ # end
193
+ #
194
+ # puts secs_to_new_year()
195
+
196
+ require 'date/format'
197
+
198
+ # Class representing a date.
199
+ #
200
+ # See the documentation to the file date.rb for an overview.
201
+ #
202
+ # Internally, the date is represented as an Astronomical
203
+ # Julian Day Number, +ajd+. The Day of Calendar Reform, +sg+, is
204
+ # also stored, for conversions to other date formats. (There
205
+ # is also an +of+ field for a time zone offset, but this
206
+ # is only for the use of the DateTime subclass.)
207
+ #
208
+ # A new Date object is created using one of the object creation
209
+ # class methods named after the corresponding date format, and the
210
+ # arguments appropriate to that date format; for instance,
211
+ # Date::civil() (aliased to Date::new()) with year, month,
212
+ # and day-of-month, or Date::ordinal() with year and day-of-year.
213
+ # All of these object creation class methods also take the
214
+ # Day of Calendar Reform as an optional argument.
215
+ #
216
+ # Date objects are immutable once created.
217
+ #
218
+ # Once a Date has been created, date values
219
+ # can be retrieved for the different date formats supported
220
+ # using instance methods. For instance, #mon() gives the
221
+ # Civil month, #cwday() gives the Commercial day of the week,
222
+ # and #yday() gives the Ordinal day of the year. Date values
223
+ # can be retrieved in any format, regardless of what format
224
+ # was used to create the Date instance.
225
+ #
226
+ # The Date class includes the Comparable module, allowing
227
+ # date objects to be compared and sorted, ranges of dates
228
+ # to be created, and so forth.
229
+ class Date
230
+
231
+ include Comparable
232
+
233
+ # Full month names, in English. Months count from 1 to 12; a
234
+ # month's numerical representation indexed into this array
235
+ # gives the name of that month (hence the first element is nil).
236
+ MONTHNAMES = [nil] + %w(January February March April May June July
237
+ August September October November December)
238
+
239
+ # Full names of days of the week, in English. Days of the week
240
+ # count from 0 to 6 (except in the commercial week); a day's numerical
241
+ # representation indexed into this array gives the name of that day.
242
+ DAYNAMES = %w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday)
243
+
244
+ # Abbreviated month names, in English.
245
+ ABBR_MONTHNAMES = [nil] + %w(Jan Feb Mar Apr May Jun
246
+ Jul Aug Sep Oct Nov Dec)
247
+
248
+ # Abbreviated day names, in English.
249
+ ABBR_DAYNAMES = %w(Sun Mon Tue Wed Thu Fri Sat)
250
+
251
+ [MONTHNAMES, DAYNAMES, ABBR_MONTHNAMES, ABBR_DAYNAMES].each do |xs|
252
+ xs.each{|x| x.freeze unless x.nil?}.freeze
253
+ end
254
+
255
+ class Infinity < Numeric # :nodoc:
256
+
257
+ include Comparable
258
+
259
+ def initialize(d=1) @d = d <=> 0 end
260
+
261
+ def d() @d end
262
+
263
+ protected :d
264
+
265
+ def zero? () false end
266
+ def finite? () false end
267
+ def infinite? () d.nonzero? end
268
+ def nan? () d.zero? end
269
+
270
+ def abs() self.class.new end
271
+
272
+ def -@ () self.class.new(-d) end
273
+ def +@ () self.class.new(+d) end
274
+
275
+ def <=> (other)
276
+ case other
277
+ when Infinity; return d <=> other.d
278
+ when Numeric; return d
279
+ else
280
+ begin
281
+ l, r = other.coerce(self)
282
+ return l <=> r
283
+ rescue NoMethodError
284
+ end
285
+ end
286
+ nil
287
+ end
288
+
289
+ def coerce(other)
290
+ case other
291
+ when Numeric; return -d, d
292
+ else
293
+ super
294
+ end
295
+ end
296
+
297
+ end
298
+
299
+ # The Julian Day Number of the Day of Calendar Reform for Italy
300
+ # and the Catholic countries.
301
+ ITALY = 2299161 # 1582-10-15
302
+
303
+ # The Julian Day Number of the Day of Calendar Reform for England
304
+ # and her Colonies.
305
+ ENGLAND = 2361222 # 1752-09-14
306
+
307
+ # A constant used to indicate that a Date should always use the
308
+ # Julian calendar.
309
+ JULIAN = Infinity.new
310
+
311
+ # A constant used to indicate that a Date should always use the
312
+ # Gregorian calendar.
313
+ GREGORIAN = -Infinity.new
314
+
315
+ HALF_DAYS_IN_DAY = Rational(1, 2) # :nodoc:
316
+ HOURS_IN_DAY = Rational(1, 24) # :nodoc:
317
+ MINUTES_IN_DAY = Rational(1, 1440) # :nodoc:
318
+ SECONDS_IN_DAY = Rational(1, 86400) # :nodoc:
319
+ MILLISECONDS_IN_DAY = Rational(1, 86400*10**3) # :nodoc:
320
+ NANOSECONDS_IN_DAY = Rational(1, 86400*10**9) # :nodoc:
321
+ MILLISECONDS_IN_SECOND = Rational(1, 10**3) # :nodoc:
322
+ NANOSECONDS_IN_SECOND = Rational(1, 10**9) # :nodoc:
323
+
324
+ MJD_EPOCH_IN_AJD = Rational(4800001, 2) # 1858-11-17 # :nodoc:
325
+ UNIX_EPOCH_IN_AJD = Rational(4881175, 2) # 1970-01-01 # :nodoc:
326
+ MJD_EPOCH_IN_CJD = 2400001 # :nodoc:
327
+ UNIX_EPOCH_IN_CJD = 2440588 # :nodoc:
328
+ LD_EPOCH_IN_CJD = 2299160 # :nodoc:
329
+
330
+ t = Module.new do
331
+
332
+ private
333
+
334
+ def find_fdoy(y, sg) # :nodoc:
335
+ j = nil
336
+ 1.upto(31) do |d|
337
+ break if j = _valid_civil?(y, 1, d, sg)
338
+ end
339
+ j
340
+ end
341
+
342
+ def find_ldoy(y, sg) # :nodoc:
343
+ j = nil
344
+ 31.downto(1) do |d|
345
+ break if j = _valid_civil?(y, 12, d, sg)
346
+ end
347
+ j
348
+ end
349
+
350
+ def find_fdom(y, m, sg) # :nodoc:
351
+ j = nil
352
+ 1.upto(31) do |d|
353
+ break if j = _valid_civil?(y, m, d, sg)
354
+ end
355
+ j
356
+ end
357
+
358
+ def find_ldom(y, m, sg) # :nodoc:
359
+ j = nil
360
+ 31.downto(1) do |d|
361
+ break if j = _valid_civil?(y, m, d, sg)
362
+ end
363
+ j
364
+ end
365
+
366
+ # Convert an Ordinal Date to a Julian Day Number.
367
+ #
368
+ # +y+ and +d+ are the year and day-of-year to convert.
369
+ # +sg+ specifies the Day of Calendar Reform.
370
+ #
371
+ # Returns the corresponding Julian Day Number.
372
+ def ordinal_to_jd(y, d, sg=GREGORIAN) # :nodoc:
373
+ find_fdoy(y, sg) + d - 1
374
+ end
375
+
376
+ # Convert a Julian Day Number to an Ordinal Date.
377
+ #
378
+ # +jd+ is the Julian Day Number to convert.
379
+ # +sg+ specifies the Day of Calendar Reform.
380
+ #
381
+ # Returns the corresponding Ordinal Date as
382
+ # [year, day_of_year]
383
+ def jd_to_ordinal(jd, sg=GREGORIAN) # :nodoc:
384
+ y = jd_to_civil(jd, sg)[0]
385
+ j = find_fdoy(y, sg)
386
+ doy = jd - j + 1
387
+ return y, doy
388
+ end
389
+
390
+ # Convert a Civil Date to a Julian Day Number.
391
+ # +y+, +m+, and +d+ are the year, month, and day of the
392
+ # month. +sg+ specifies the Day of Calendar Reform.
393
+ #
394
+ # Returns the corresponding Julian Day Number.
395
+ def civil_to_jd(y, m, d, sg=GREGORIAN) # :nodoc:
396
+ if m <= 2
397
+ y -= 1
398
+ m += 12
399
+ end
400
+ a = (y / 100.0).floor
401
+ b = 2 - a + (a / 4.0).floor
402
+ jd = (365.25 * (y + 4716)).floor +
403
+ (30.6001 * (m + 1)).floor +
404
+ d + b - 1524
405
+ if jd < sg
406
+ jd -= b
407
+ end
408
+ jd
409
+ end
410
+
411
+ # Convert a Julian Day Number to a Civil Date. +jd+ is
412
+ # the Julian Day Number. +sg+ specifies the Day of
413
+ # Calendar Reform.
414
+ #
415
+ # Returns the corresponding [year, month, day_of_month]
416
+ # as a three-element array.
417
+ def jd_to_civil(jd, sg=GREGORIAN) # :nodoc:
418
+ if jd < sg
419
+ a = jd
420
+ else
421
+ x = ((jd - 1867216.25) / 36524.25).floor
422
+ a = jd + 1 + x - (x / 4.0).floor
423
+ end
424
+ b = a + 1524
425
+ c = ((b - 122.1) / 365.25).floor
426
+ d = (365.25 * c).floor
427
+ e = ((b - d) / 30.6001).floor
428
+ dom = b - d - (30.6001 * e).floor
429
+ if e <= 13
430
+ m = e - 1
431
+ y = c - 4716
432
+ else
433
+ m = e - 13
434
+ y = c - 4715
435
+ end
436
+ return y, m, dom
437
+ end
438
+
439
+ # Convert a Commercial Date to a Julian Day Number.
440
+ #
441
+ # +y+, +w+, and +d+ are the (commercial) year, week of the year,
442
+ # and day of the week of the Commercial Date to convert.
443
+ # +sg+ specifies the Day of Calendar Reform.
444
+ def commercial_to_jd(y, w, d, sg=GREGORIAN) # :nodoc:
445
+ j = find_fdoy(y, sg) + 3
446
+ (j - (((j - 1) + 1) % 7)) +
447
+ 7 * (w - 1) +
448
+ (d - 1)
449
+ end
450
+
451
+ # Convert a Julian Day Number to a Commercial Date
452
+ #
453
+ # +jd+ is the Julian Day Number to convert.
454
+ # +sg+ specifies the Day of Calendar Reform.
455
+ #
456
+ # Returns the corresponding Commercial Date as
457
+ # [commercial_year, week_of_year, day_of_week]
458
+ def jd_to_commercial(jd, sg=GREGORIAN) # :nodoc:
459
+ a = jd_to_civil(jd - 3, sg)[0]
460
+ y = if jd >= commercial_to_jd(a + 1, 1, 1, sg) then a + 1 else a end
461
+ w = 1 + ((jd - commercial_to_jd(y, 1, 1, sg)) / 7).floor
462
+ d = (jd + 1) % 7
463
+ d = 7 if d == 0
464
+ return y, w, d
465
+ end
466
+
467
+ def weeknum_to_jd(y, w, d, f=0, sg=GREGORIAN) # :nodoc:
468
+ a = find_fdoy(y, sg) + 6
469
+ (a - ((a - f) + 1) % 7 - 7) + 7 * w + d
470
+ end
471
+
472
+ def jd_to_weeknum(jd, f=0, sg=GREGORIAN) # :nodoc:
473
+ y, m, d = jd_to_civil(jd, sg)
474
+ a = find_fdoy(y, sg) + 6
475
+ w, d = (jd - (a - ((a - f) + 1) % 7) + 7).divmod(7)
476
+ return y, w, d
477
+ end
478
+
479
+ def nth_kday_to_jd(y, m, n, k, sg=GREGORIAN) # :nodoc:
480
+ j = if n > 0
481
+ find_fdom(y, m, sg) - 1
482
+ else
483
+ find_ldom(y, m, sg) + 7
484
+ end
485
+ (j - (((j - k) + 1) % 7)) + 7 * n
486
+ end
487
+
488
+ def jd_to_nth_kday(jd, sg=GREGORIAN) # :nodoc:
489
+ y, m, d = jd_to_civil(jd, sg)
490
+ j = find_fdom(y, m, sg)
491
+ return y, m, ((jd - j) / 7).floor + 1, jd_to_wday(jd)
492
+ end
493
+
494
+ # Convert an Astronomical Julian Day Number to a (civil) Julian
495
+ # Day Number.
496
+ #
497
+ # +ajd+ is the Astronomical Julian Day Number to convert.
498
+ # +of+ is the offset from UTC as a fraction of a day (defaults to 0).
499
+ #
500
+ # Returns the (civil) Julian Day Number as [day_number,
501
+ # fraction] where +fraction+ is always 1/2.
502
+ def ajd_to_jd(ajd, of=0) (ajd + of + HALF_DAYS_IN_DAY).divmod(1) end # :nodoc:
503
+
504
+ # Convert a (civil) Julian Day Number to an Astronomical Julian
505
+ # Day Number.
506
+ #
507
+ # +jd+ is the Julian Day Number to convert, and +fr+ is a
508
+ # fractional day.
509
+ # +of+ is the offset from UTC as a fraction of a day (defaults to 0).
510
+ #
511
+ # Returns the Astronomical Julian Day Number as a single
512
+ # numeric value.
513
+ def jd_to_ajd(jd, fr, of=0) jd + fr - of - HALF_DAYS_IN_DAY end # :nodoc:
514
+
515
+ # Convert a fractional day +fr+ to [hours, minutes, seconds,
516
+ # fraction_of_a_second]
517
+ def day_fraction_to_time(fr) # :nodoc:
518
+ ss, fr = fr.divmod(SECONDS_IN_DAY) # 4p
519
+ h, ss = ss.divmod(3600)
520
+ min, s = ss.divmod(60)
521
+ return h, min, s, fr * 86400
522
+ end
523
+
524
+ # Convert an +h+ hour, +min+ minutes, +s+ seconds period
525
+ # to a fractional day.
526
+ begin
527
+ Rational(Rational(1, 2), 2) # a challenge
528
+
529
+ def time_to_day_fraction(h, min, s)
530
+ Rational(h * 3600 + min * 60 + s, 86400) # 4p
531
+ end
532
+ rescue
533
+ def time_to_day_fraction(h, min, s)
534
+ if Integer === h && Integer === min && Integer === s
535
+ Rational(h * 3600 + min * 60 + s, 86400) # 4p
536
+ else
537
+ (h * 3600 + min * 60 + s).to_r/86400 # 4p
538
+ end
539
+ end
540
+ end
541
+
542
+ # Convert an Astronomical Modified Julian Day Number to an
543
+ # Astronomical Julian Day Number.
544
+ def amjd_to_ajd(amjd) amjd + MJD_EPOCH_IN_AJD end # :nodoc:
545
+
546
+ # Convert an Astronomical Julian Day Number to an
547
+ # Astronomical Modified Julian Day Number.
548
+ def ajd_to_amjd(ajd) ajd - MJD_EPOCH_IN_AJD end # :nodoc:
549
+
550
+ # Convert a Modified Julian Day Number to a Julian
551
+ # Day Number.
552
+ def mjd_to_jd(mjd) mjd + MJD_EPOCH_IN_CJD end # :nodoc:
553
+
554
+ # Convert a Julian Day Number to a Modified Julian Day
555
+ # Number.
556
+ def jd_to_mjd(jd) jd - MJD_EPOCH_IN_CJD end # :nodoc:
557
+
558
+ # Convert a count of the number of days since the adoption
559
+ # of the Gregorian Calendar (in Italy) to a Julian Day Number.
560
+ def ld_to_jd(ld) ld + LD_EPOCH_IN_CJD end # :nodoc:
561
+
562
+ # Convert a Julian Day Number to the number of days since
563
+ # the adoption of the Gregorian Calendar (in Italy).
564
+ def jd_to_ld(jd) jd - LD_EPOCH_IN_CJD end # :nodoc:
565
+
566
+ # Convert a Julian Day Number to the day of the week.
567
+ #
568
+ # Sunday is day-of-week 0; Saturday is day-of-week 6.
569
+ def jd_to_wday(jd) (jd + 1) % 7 end # :nodoc:
570
+
571
+ # Is +jd+ a valid Julian Day Number?
572
+ #
573
+ # If it is, returns it. In fact, any value is treated as a valid
574
+ # Julian Day Number.
575
+ def _valid_jd? (jd, sg=GREGORIAN) jd end # :nodoc:
576
+
577
+ # Do the year +y+ and day-of-year +d+ make a valid Ordinal Date?
578
+ # Returns the corresponding Julian Day Number if they do, or
579
+ # nil if they don't.
580
+ #
581
+ # +d+ can be a negative number, in which case it counts backwards
582
+ # from the end of the year (-1 being the last day of the year).
583
+ # No year wraparound is performed, however, so valid values of
584
+ # +d+ are -365 .. -1, 1 .. 365 on a non-leap-year,
585
+ # -366 .. -1, 1 .. 366 on a leap year.
586
+ # A date falling in the period skipped in the Day of Calendar Reform
587
+ # adjustment is not valid.
588
+ #
589
+ # +sg+ specifies the Day of Calendar Reform.
590
+ def _valid_ordinal? (y, d, sg=GREGORIAN) # :nodoc:
591
+ if d < 0
592
+ j = find_ldoy(y, sg)
593
+ ny, nd = jd_to_ordinal(j + d + 1, sg)
594
+ return unless ny == y
595
+ d = nd
596
+ end
597
+ jd = ordinal_to_jd(y, d, sg)
598
+ return unless [y, d] == jd_to_ordinal(jd, sg)
599
+ jd
600
+ end
601
+
602
+ # Do year +y+, month +m+, and day-of-month +d+ make a
603
+ # valid Civil Date? Returns the corresponding Julian
604
+ # Day Number if they do, nil if they don't.
605
+ #
606
+ # +m+ and +d+ can be negative, in which case they count
607
+ # backwards from the end of the year and the end of the
608
+ # month respectively. No wraparound is performed, however,
609
+ # and invalid values cause an ArgumentError to be raised.
610
+ # A date falling in the period skipped in the Day of Calendar
611
+ # Reform adjustment is not valid.
612
+ #
613
+ # +sg+ specifies the Day of Calendar Reform.
614
+ def _valid_civil? (y, m, d, sg=GREGORIAN) # :nodoc:
615
+ if m < 0
616
+ m += 13
617
+ end
618
+ if d < 0
619
+ j = find_ldom(y, m, sg)
620
+ ny, nm, nd = jd_to_civil(j + d + 1, sg)
621
+ return unless [ny, nm] == [y, m]
622
+ d = nd
623
+ end
624
+ jd = civil_to_jd(y, m, d, sg)
625
+ return unless [y, m, d] == jd_to_civil(jd, sg)
626
+ jd
627
+ end
628
+
629
+ # Do year +y+, week-of-year +w+, and day-of-week +d+ make a
630
+ # valid Commercial Date? Returns the corresponding Julian
631
+ # Day Number if they do, nil if they don't.
632
+ #
633
+ # Monday is day-of-week 1; Sunday is day-of-week 7.
634
+ #
635
+ # +w+ and +d+ can be negative, in which case they count
636
+ # backwards from the end of the year and the end of the
637
+ # week respectively. No wraparound is performed, however,
638
+ # and invalid values cause an ArgumentError to be raised.
639
+ # A date falling in the period skipped in the Day of Calendar
640
+ # Reform adjustment is not valid.
641
+ #
642
+ # +sg+ specifies the Day of Calendar Reform.
643
+ def _valid_commercial? (y, w, d, sg=GREGORIAN) # :nodoc:
644
+ if d < 0
645
+ d += 8
646
+ end
647
+ if w < 0
648
+ ny, nw, nd =
649
+ jd_to_commercial(commercial_to_jd(y + 1, 1, 1, sg) + w * 7, sg)
650
+ return unless ny == y
651
+ w = nw
652
+ end
653
+ jd = commercial_to_jd(y, w, d, sg)
654
+ return unless [y, w, d] == jd_to_commercial(jd, sg)
655
+ jd
656
+ end
657
+
658
+ def _valid_weeknum? (y, w, d, f, sg=GREGORIAN) # :nodoc:
659
+ if d < 0
660
+ d += 7
661
+ end
662
+ if w < 0
663
+ ny, nw, nd, nf =
664
+ jd_to_weeknum(weeknum_to_jd(y + 1, 1, f, f, sg) + w * 7, f, sg)
665
+ return unless ny == y
666
+ w = nw
667
+ end
668
+ jd = weeknum_to_jd(y, w, d, f, sg)
669
+ return unless [y, w, d] == jd_to_weeknum(jd, f, sg)
670
+ jd
671
+ end
672
+
673
+ def _valid_nth_kday? (y, m, n, k, sg=GREGORIAN) # :nodoc:
674
+ if k < 0
675
+ k += 7
676
+ end
677
+ if n < 0
678
+ ny, nm = (y * 12 + m).divmod(12)
679
+ nm, = (nm + 1) .divmod(1)
680
+ ny, nm, nn, nk =
681
+ jd_to_nth_kday(nth_kday_to_jd(ny, nm, 1, k, sg) + n * 7, sg)
682
+ return unless [ny, nm] == [y, m]
683
+ n = nn
684
+ end
685
+ jd = nth_kday_to_jd(y, m, n, k, sg)
686
+ return unless [y, m, n, k] == jd_to_nth_kday(jd, sg)
687
+ jd
688
+ end
689
+
690
+ # Do hour +h+, minute +min+, and second +s+ constitute a valid time?
691
+ #
692
+ # If they do, returns their value as a fraction of a day. If not,
693
+ # returns nil.
694
+ #
695
+ # The 24-hour clock is used. Negative values of +h+, +min+, and
696
+ # +sec+ are treating as counting backwards from the end of the
697
+ # next larger unit (e.g. a +min+ of -2 is treated as 58). No
698
+ # wraparound is performed.
699
+ def _valid_time? (h, min, s) # :nodoc:
700
+ h += 24 if h < 0
701
+ min += 60 if min < 0
702
+ s += 60 if s < 0
703
+ return unless ((0...24) === h &&
704
+ (0...60) === min &&
705
+ (0...60) === s) ||
706
+ (24 == h &&
707
+ 0 == min &&
708
+ 0 == s)
709
+ time_to_day_fraction(h, min, s)
710
+ end
711
+
712
+ end
713
+
714
+ extend t
715
+ include t
716
+
717
+ # Is a year a leap year in the Julian calendar?
718
+ #
719
+ # All years divisible by 4 are leap years in the Julian calendar.
720
+ def self.julian_leap? (y) y % 4 == 0 end
721
+
722
+ # Is a year a leap year in the Gregorian calendar?
723
+ #
724
+ # All years divisible by 4 are leap years in the Gregorian calendar,
725
+ # except for years divisible by 100 and not by 400.
726
+ def self.gregorian_leap? (y) y % 4 == 0 && y % 100 != 0 || y % 400 == 0 end
727
+
728
+ class << self; alias_method :leap?, :gregorian_leap? end
729
+ class << self; alias_method :new!, :new end
730
+
731
+ def self.valid_jd? (jd, sg=ITALY)
732
+ !!_valid_jd?(jd, sg)
733
+ end
734
+
735
+ def self.valid_ordinal? (y, d, sg=ITALY)
736
+ !!_valid_ordinal?(y, d, sg)
737
+ end
738
+
739
+ def self.valid_civil? (y, m, d, sg=ITALY)
740
+ !!_valid_civil?(y, m, d, sg)
741
+ end
742
+
743
+ class << self; alias_method :valid_date?, :valid_civil? end
744
+
745
+ def self.valid_commercial? (y, w, d, sg=ITALY)
746
+ !!_valid_commercial?(y, w, d, sg)
747
+ end
748
+
749
+ def self.valid_weeknum? (y, w, d, f, sg=ITALY) # :nodoc:
750
+ !!_valid_weeknum?(y, w, d, f, sg)
751
+ end
752
+
753
+ private_class_method :valid_weeknum?
754
+
755
+ def self.valid_nth_kday? (y, m, n, k, sg=ITALY) # :nodoc:
756
+ !!_valid_nth_kday?(y, m, n, k, sg)
757
+ end
758
+
759
+ private_class_method :valid_nth_kday?
760
+
761
+ def self.valid_time? (h, min, s) # :nodoc:
762
+ !!_valid_time?(h, min, s)
763
+ end
764
+
765
+ private_class_method :valid_time?
766
+
767
+ # Create a new Date object from a Julian Day Number.
768
+ #
769
+ # +jd+ is the Julian Day Number; if not specified, it defaults to
770
+ # 0.
771
+ # +sg+ specifies the Day of Calendar Reform.
772
+ def self.jd(jd=0, sg=ITALY)
773
+ jd = _valid_jd?(jd, sg)
774
+ new!(jd_to_ajd(jd, 0, 0), 0, sg)
775
+ end
776
+
777
+ # Create a new Date object from an Ordinal Date, specified
778
+ # by year +y+ and day-of-year +d+. +d+ can be negative,
779
+ # in which it counts backwards from the end of the year.
780
+ # No year wraparound is performed, however. An invalid
781
+ # value for +d+ results in an ArgumentError being raised.
782
+ #
783
+ # +y+ defaults to -4712, and +d+ to 1; this is Julian Day
784
+ # Number day 0.
785
+ #
786
+ # +sg+ specifies the Day of Calendar Reform.
787
+ def self.ordinal(y=-4712, d=1, sg=ITALY)
788
+ unless jd = _valid_ordinal?(y, d, sg)
789
+ raise ArgumentError, 'invalid date'
790
+ end
791
+ new!(jd_to_ajd(jd, 0, 0), 0, sg)
792
+ end
793
+
794
+ # Create a new Date object for the Civil Date specified by
795
+ # year +y+, month +m+, and day-of-month +d+.
796
+ #
797
+ # +m+ and +d+ can be negative, in which case they count
798
+ # backwards from the end of the year and the end of the
799
+ # month respectively. No wraparound is performed, however,
800
+ # and invalid values cause an ArgumentError to be raised.
801
+ # can be negative
802
+ #
803
+ # +y+ defaults to -4712, +m+ to 1, and +d+ to 1; this is
804
+ # Julian Day Number day 0.
805
+ #
806
+ # +sg+ specifies the Day of Calendar Reform.
807
+ def self.civil(y=-4712, m=1, d=1, sg=ITALY)
808
+ unless jd = _valid_civil?(y, m, d, sg)
809
+ raise ArgumentError, 'invalid date'
810
+ end
811
+ new!(jd_to_ajd(jd, 0, 0), 0, sg)
812
+ end
813
+
814
+ class << self; alias_method :new, :civil end
815
+
816
+ # Create a new Date object for the Commercial Date specified by
817
+ # year +y+, week-of-year +w+, and day-of-week +d+.
818
+ #
819
+ # Monday is day-of-week 1; Sunday is day-of-week 7.
820
+ #
821
+ # +w+ and +d+ can be negative, in which case they count
822
+ # backwards from the end of the year and the end of the
823
+ # week respectively. No wraparound is performed, however,
824
+ # and invalid values cause an ArgumentError to be raised.
825
+ #
826
+ # +y+ defaults to -4712, +w+ to 1, and +d+ to 1; this is
827
+ # Julian Day Number day 0.
828
+ #
829
+ # +sg+ specifies the Day of Calendar Reform.
830
+ def self.commercial(y=-4712, w=1, d=1, sg=ITALY)
831
+ unless jd = _valid_commercial?(y, w, d, sg)
832
+ raise ArgumentError, 'invalid date'
833
+ end
834
+ new!(jd_to_ajd(jd, 0, 0), 0, sg)
835
+ end
836
+
837
+ def self.weeknum(y=-4712, w=0, d=1, f=0, sg=ITALY)
838
+ unless jd = _valid_weeknum?(y, w, d, f, sg)
839
+ raise ArgumentError, 'invalid date'
840
+ end
841
+ new!(jd_to_ajd(jd, 0, 0), 0, sg)
842
+ end
843
+
844
+ private_class_method :weeknum
845
+
846
+ def self.nth_kday(y=-4712, m=1, n=1, k=1, sg=ITALY)
847
+ unless jd = _valid_nth_kday?(y, m, n, k, sg)
848
+ raise ArgumentError, 'invalid date'
849
+ end
850
+ new!(jd_to_ajd(jd, 0, 0), 0, sg)
851
+ end
852
+
853
+ private_class_method :nth_kday
854
+
855
+ def self.rewrite_frags(elem) # :nodoc:
856
+ elem ||= {}
857
+ if seconds = elem[:seconds]
858
+ d, fr = seconds.divmod(86400)
859
+ h, fr = fr.divmod(3600)
860
+ min, fr = fr.divmod(60)
861
+ s, fr = fr.divmod(1)
862
+ elem[:jd] = UNIX_EPOCH_IN_CJD + d
863
+ elem[:hour] = h
864
+ elem[:min] = min
865
+ elem[:sec] = s
866
+ elem[:sec_fraction] = fr
867
+ elem.delete(:seconds)
868
+ elem.delete(:offset)
869
+ end
870
+ elem
871
+ end
872
+
873
+ private_class_method :rewrite_frags
874
+
875
+ def self.complete_frags(elem) # :nodoc:
876
+ i = 0
877
+ g = [[:time, [:hour, :min, :sec]],
878
+ [nil, [:jd]],
879
+ [:ordinal, [:year, :yday, :hour, :min, :sec]],
880
+ [:civil, [:year, :mon, :mday, :hour, :min, :sec]],
881
+ [:commercial, [:cwyear, :cweek, :cwday, :hour, :min, :sec]],
882
+ [:wday, [:wday, :hour, :min, :sec]],
883
+ [:wnum0, [:year, :wnum0, :wday, :hour, :min, :sec]],
884
+ [:wnum1, [:year, :wnum1, :wday, :hour, :min, :sec]],
885
+ [nil, [:cwyear, :cweek, :wday, :hour, :min, :sec]],
886
+ [nil, [:year, :wnum0, :cwday, :hour, :min, :sec]],
887
+ [nil, [:year, :wnum1, :cwday, :hour, :min, :sec]]].
888
+ collect{|k, a| e = elem.values_at(*a).compact; [k, a, e]}.
889
+ select{|k, a, e| e.size > 0}.
890
+ sort_by{|k, a, e| [e.size, i -= 1]}.last
891
+
892
+ d = nil
893
+
894
+ if g && g[0] && (g[1].size - g[2].size) != 0
895
+ d ||= Date.today
896
+
897
+ case g[0]
898
+ when :ordinal
899
+ elem[:year] ||= d.year
900
+ elem[:yday] ||= 1
901
+ when :civil
902
+ g[1].each do |e|
903
+ break if elem[e]
904
+ elem[e] = d.__send__(e)
905
+ end
906
+ elem[:mon] ||= 1
907
+ elem[:mday] ||= 1
908
+ when :commercial
909
+ g[1].each do |e|
910
+ break if elem[e]
911
+ elem[e] = d.__send__(e)
912
+ end
913
+ elem[:cweek] ||= 1
914
+ elem[:cwday] ||= 1
915
+ when :wday
916
+ elem[:jd] ||= (d - d.wday + elem[:wday]).jd
917
+ when :wnum0
918
+ g[1].each do |e|
919
+ break if elem[e]
920
+ elem[e] = d.__send__(e)
921
+ end
922
+ elem[:wnum0] ||= 0
923
+ elem[:wday] ||= 0
924
+ when :wnum1
925
+ g[1].each do |e|
926
+ break if elem[e]
927
+ elem[e] = d.__send__(e)
928
+ end
929
+ elem[:wnum1] ||= 0
930
+ elem[:wday] ||= 0
931
+ end
932
+ end
933
+
934
+ if g && g[0] == :time
935
+ if self <= DateTime
936
+ d ||= Date.today
937
+ elem[:jd] ||= d.jd
938
+ end
939
+ end
940
+
941
+ elem[:hour] ||= 0
942
+ elem[:min] ||= 0
943
+ elem[:sec] ||= 0
944
+ elem[:sec] = [elem[:sec], 59].min
945
+
946
+ elem
947
+ end
948
+
949
+ private_class_method :complete_frags
950
+
951
+ def self.valid_date_frags?(elem, sg) # :nodoc:
952
+ catch :jd do
953
+ a = elem.values_at(:jd)
954
+ if a.all?
955
+ if jd = _valid_jd?(*(a << sg))
956
+ throw :jd, jd
957
+ end
958
+ end
959
+
960
+ a = elem.values_at(:year, :yday)
961
+ if a.all?
962
+ if jd = _valid_ordinal?(*(a << sg))
963
+ throw :jd, jd
964
+ end
965
+ end
966
+
967
+ a = elem.values_at(:year, :mon, :mday)
968
+ if a.all?
969
+ if jd = _valid_civil?(*(a << sg))
970
+ throw :jd, jd
971
+ end
972
+ end
973
+
974
+ a = elem.values_at(:cwyear, :cweek, :cwday)
975
+ if a[2].nil? && elem[:wday]
976
+ a[2] = elem[:wday].nonzero? || 7
977
+ end
978
+ if a.all?
979
+ if jd = _valid_commercial?(*(a << sg))
980
+ throw :jd, jd
981
+ end
982
+ end
983
+
984
+ a = elem.values_at(:year, :wnum0, :wday)
985
+ if a[2].nil? && elem[:cwday]
986
+ a[2] = elem[:cwday] % 7
987
+ end
988
+ if a.all?
989
+ if jd = _valid_weeknum?(*(a << 0 << sg))
990
+ throw :jd, jd
991
+ end
992
+ end
993
+
994
+ a = elem.values_at(:year, :wnum1, :wday)
995
+ if a[2]
996
+ a[2] = (a[2] - 1) % 7
997
+ end
998
+ if a[2].nil? && elem[:cwday]
999
+ a[2] = (elem[:cwday] - 1) % 7
1000
+ end
1001
+ if a.all?
1002
+ if jd = _valid_weeknum?(*(a << 1 << sg))
1003
+ throw :jd, jd
1004
+ end
1005
+ end
1006
+ end
1007
+ end
1008
+
1009
+ private_class_method :valid_date_frags?
1010
+
1011
+ def self.valid_time_frags? (elem) # :nodoc:
1012
+ h, min, s = elem.values_at(:hour, :min, :sec)
1013
+ _valid_time?(h, min, s)
1014
+ end
1015
+
1016
+ private_class_method :valid_time_frags?
1017
+
1018
+ def self.new_by_frags(elem, sg) # :nodoc:
1019
+ elem = rewrite_frags(elem)
1020
+ elem = complete_frags(elem)
1021
+ unless jd = valid_date_frags?(elem, sg)
1022
+ raise ArgumentError, 'invalid date'
1023
+ end
1024
+ new!(jd_to_ajd(jd, 0, 0), 0, sg)
1025
+ end
1026
+
1027
+ private_class_method :new_by_frags
1028
+
1029
+ # Create a new Date object by parsing from a String
1030
+ # according to a specified format.
1031
+ #
1032
+ # +str+ is a String holding a date representation.
1033
+ # +fmt+ is the format that the date is in. See
1034
+ # date/format.rb for details on supported formats.
1035
+ #
1036
+ # The default +str+ is '-4712-01-01', and the default
1037
+ # +fmt+ is '%F', which means Year-Month-Day_of_Month.
1038
+ # This gives Julian Day Number day 0.
1039
+ #
1040
+ # +sg+ specifies the Day of Calendar Reform.
1041
+ #
1042
+ # An ArgumentError will be raised if +str+ cannot be
1043
+ # parsed.
1044
+ def self.strptime(str='-4712-01-01', fmt='%F', sg=ITALY)
1045
+ elem = _strptime(str, fmt)
1046
+ new_by_frags(elem, sg)
1047
+ end
1048
+
1049
+ # Create a new Date object by parsing from a String,
1050
+ # without specifying the format.
1051
+ #
1052
+ # +str+ is a String holding a date representation.
1053
+ # +comp+ specifies whether to interpret 2-digit years
1054
+ # as 19XX (>= 69) or 20XX (< 69); the default is not to.
1055
+ # The method will attempt to parse a date from the String
1056
+ # using various heuristics; see #_parse in date/format.rb
1057
+ # for more details. If parsing fails, an ArgumentError
1058
+ # will be raised.
1059
+ #
1060
+ # The default +str+ is '-4712-01-01'; this is Julian
1061
+ # Day Number day 0.
1062
+ #
1063
+ # +sg+ specifies the Day of Calendar Reform.
1064
+ def self.parse(str='-4712-01-01', comp=true, sg=ITALY)
1065
+ elem = _parse(str, comp)
1066
+ new_by_frags(elem, sg)
1067
+ end
1068
+
1069
+ def self.iso8601(str='-4712-01-01', sg=ITALY) # :nodoc:
1070
+ elem = _iso8601(str)
1071
+ new_by_frags(elem, sg)
1072
+ end
1073
+
1074
+ def self.rfc3339(str='-4712-01-01T00:00:00+00:00', sg=ITALY) # :nodoc:
1075
+ elem = _rfc3339(str)
1076
+ new_by_frags(elem, sg)
1077
+ end
1078
+
1079
+ def self.xmlschema(str='-4712-01-01', sg=ITALY) # :nodoc:
1080
+ elem = _xmlschema(str)
1081
+ new_by_frags(elem, sg)
1082
+ end
1083
+
1084
+ def self.rfc2822(str='Mon, 1 Jan -4712 00:00:00 +0000', sg=ITALY) # :nodoc:
1085
+ elem = _rfc2822(str)
1086
+ new_by_frags(elem, sg)
1087
+ end
1088
+
1089
+ class << self; alias_method :rfc822, :rfc2822 end
1090
+
1091
+ def self.httpdate(str='Mon, 01 Jan -4712 00:00:00 GMT', sg=ITALY) # :nodoc:
1092
+ elem = _httpdate(str)
1093
+ new_by_frags(elem, sg)
1094
+ end
1095
+
1096
+ def self.jisx0301(str='-4712-01-01', sg=ITALY) # :nodoc:
1097
+ elem = _jisx0301(str)
1098
+ new_by_frags(elem, sg)
1099
+ end
1100
+
1101
+ class << self
1102
+
1103
+ def once(*ids) # :nodoc: -- restricted
1104
+ for id in ids
1105
+ module_eval <<-"end;"
1106
+ alias_method :__#{id.object_id}__, :#{id.to_s}
1107
+ private :__#{id.object_id}__
1108
+ def #{id.to_s}(*args)
1109
+ @__ca__[#{id.object_id}] ||= __#{id.object_id}__(*args)
1110
+ end
1111
+ end;
1112
+ end
1113
+ end
1114
+
1115
+ private :once
1116
+
1117
+ end
1118
+
1119
+ # *NOTE* this is the documentation for the method new!(). If
1120
+ # you are reading this as the documentation for new(), that is
1121
+ # because rdoc doesn't fully support the aliasing of the
1122
+ # initialize() method.
1123
+ # new() is in
1124
+ # fact an alias for #civil(): read the documentation for that
1125
+ # method instead.
1126
+ #
1127
+ # Create a new Date object.
1128
+ #
1129
+ # +ajd+ is the Astronomical Julian Day Number.
1130
+ # +of+ is the offset from UTC as a fraction of a day.
1131
+ # Both default to 0.
1132
+ #
1133
+ # +sg+ specifies the Day of Calendar Reform to use for this
1134
+ # Date object.
1135
+ #
1136
+ # Using one of the factory methods such as Date::civil is
1137
+ # generally easier and safer.
1138
+ def initialize(ajd=0, of=0, sg=ITALY)
1139
+ @ajd, @of, @sg = ajd, of, sg
1140
+ @__ca__ = {}
1141
+ end
1142
+
1143
+ # Get the date as an Astronomical Julian Day Number.
1144
+ def ajd() @ajd end
1145
+
1146
+ # Get the date as an Astronomical Modified Julian Day Number.
1147
+ def amjd() ajd_to_amjd(@ajd) end
1148
+
1149
+ once :amjd
1150
+
1151
+ # Get the date as a Julian Day Number.
1152
+ def jd() ajd_to_jd(@ajd, @of)[0] end
1153
+
1154
+ # Get any fractional day part of the date.
1155
+ def day_fraction() ajd_to_jd(@ajd, @of)[1] end
1156
+
1157
+ # Get the date as a Modified Julian Day Number.
1158
+ def mjd() jd_to_mjd(jd) end
1159
+
1160
+ # Get the date as the number of days since the Day of Calendar
1161
+ # Reform (in Italy and the Catholic countries).
1162
+ def ld() jd_to_ld(jd) end
1163
+
1164
+ once :jd, :day_fraction, :mjd, :ld
1165
+
1166
+ # Get the date as a Civil Date, [year, month, day_of_month]
1167
+ def civil() jd_to_civil(jd, @sg) end # :nodoc:
1168
+
1169
+ # Get the date as an Ordinal Date, [year, day_of_year]
1170
+ def ordinal() jd_to_ordinal(jd, @sg) end # :nodoc:
1171
+
1172
+ # Get the date as a Commercial Date, [year, week_of_year, day_of_week]
1173
+ def commercial() jd_to_commercial(jd, @sg) end # :nodoc:
1174
+
1175
+ def weeknum0() jd_to_weeknum(jd, 0, @sg) end # :nodoc:
1176
+ def weeknum1() jd_to_weeknum(jd, 1, @sg) end # :nodoc:
1177
+
1178
+ once :civil, :ordinal, :commercial, :weeknum0, :weeknum1
1179
+ private :civil, :ordinal, :commercial, :weeknum0, :weeknum1
1180
+
1181
+ # Get the year of this date.
1182
+ def year() civil[0] end
1183
+
1184
+ # Get the day-of-the-year of this date.
1185
+ #
1186
+ # January 1 is day-of-the-year 1
1187
+ def yday() ordinal[1] end
1188
+
1189
+ # Get the month of this date.
1190
+ #
1191
+ # January is month 1.
1192
+ def mon() civil[1] end
1193
+
1194
+ # Get the day-of-the-month of this date.
1195
+ def mday() civil[2] end
1196
+
1197
+ alias_method :month, :mon
1198
+ alias_method :day, :mday
1199
+
1200
+ def wnum0() weeknum0[1] end # :nodoc:
1201
+ def wnum1() weeknum1[1] end # :nodoc:
1202
+
1203
+ private :wnum0, :wnum1
1204
+
1205
+ # Get the time of this date as [hours, minutes, seconds,
1206
+ # fraction_of_a_second]
1207
+ def time() day_fraction_to_time(day_fraction) end # :nodoc:
1208
+
1209
+ once :time
1210
+ private :time
1211
+
1212
+ # Get the hour of this date.
1213
+ def hour() time[0] end
1214
+
1215
+ # Get the minute of this date.
1216
+ def min() time[1] end
1217
+
1218
+ # Get the second of this date.
1219
+ def sec() time[2] end
1220
+
1221
+ # Get the fraction-of-a-second of this date.
1222
+ def sec_fraction() time[3] end
1223
+
1224
+ alias_method :minute, :min
1225
+ alias_method :second, :sec
1226
+ alias_method :second_fraction, :sec_fraction
1227
+
1228
+ private :hour, :min, :sec, :sec_fraction,
1229
+ :minute, :second, :second_fraction
1230
+
1231
+ def zone() strftime('%:z') end
1232
+
1233
+ private :zone
1234
+
1235
+ # Get the commercial year of this date. See *Commercial* *Date*
1236
+ # in the introduction for how this differs from the normal year.
1237
+ def cwyear() commercial[0] end
1238
+
1239
+ # Get the commercial week of the year of this date.
1240
+ def cweek() commercial[1] end
1241
+
1242
+ # Get the commercial day of the week of this date. Monday is
1243
+ # commercial day-of-week 1; Sunday is commercial day-of-week 7.
1244
+ def cwday() commercial[2] end
1245
+
1246
+ # Get the week day of this date. Sunday is day-of-week 0;
1247
+ # Saturday is day-of-week 6.
1248
+ def wday() jd_to_wday(jd) end
1249
+
1250
+ once :wday
1251
+
1252
+ =begin
1253
+ MONTHNAMES.each_with_index do |n, i|
1254
+ if n
1255
+ define_method(n.downcase + '?'){mon == i}
1256
+ end
1257
+ end
1258
+ =end
1259
+
1260
+ DAYNAMES.each_with_index do |n, i|
1261
+ define_method(n.downcase + '?'){wday == i}
1262
+ end
1263
+
1264
+ def nth_kday? (n, k)
1265
+ k == wday && jd === nth_kday_to_jd(year, mon, n, k, start)
1266
+ end
1267
+
1268
+ private :nth_kday?
1269
+
1270
+ # Is the current date old-style (Julian Calendar)?
1271
+ def julian? () jd < @sg end
1272
+
1273
+ # Is the current date new-style (Gregorian Calendar)?
1274
+ def gregorian? () !julian? end
1275
+
1276
+ once :julian?, :gregorian?
1277
+
1278
+ def fix_style # :nodoc:
1279
+ if julian?
1280
+ then self.class::JULIAN
1281
+ else self.class::GREGORIAN end
1282
+ end
1283
+
1284
+ private :fix_style
1285
+
1286
+ # Is this a leap year?
1287
+ def leap?
1288
+ jd_to_civil(civil_to_jd(year, 3, 1, fix_style) - 1,
1289
+ fix_style)[-1] == 29
1290
+ end
1291
+
1292
+ once :leap?
1293
+
1294
+ # When is the Day of Calendar Reform for this Date object?
1295
+ def start() @sg end
1296
+
1297
+ # Create a copy of this Date object using a new Day of Calendar Reform.
1298
+ def new_start(sg=self.class::ITALY) self.class.new!(@ajd, @of, sg) end
1299
+
1300
+ # Create a copy of this Date object that uses the Italian/Catholic
1301
+ # Day of Calendar Reform.
1302
+ def italy() new_start(self.class::ITALY) end
1303
+
1304
+ # Create a copy of this Date object that uses the English/Colonial
1305
+ # Day of Calendar Reform.
1306
+ def england() new_start(self.class::ENGLAND) end
1307
+
1308
+ # Create a copy of this Date object that always uses the Julian
1309
+ # Calendar.
1310
+ def julian() new_start(self.class::JULIAN) end
1311
+
1312
+ # Create a copy of this Date object that always uses the Gregorian
1313
+ # Calendar.
1314
+ def gregorian() new_start(self.class::GREGORIAN) end
1315
+
1316
+ def offset() @of end
1317
+
1318
+ def new_offset(of=0)
1319
+ if String === of
1320
+ of = Rational(zone_to_diff(of) || 0, 86400)
1321
+ end
1322
+ self.class.new!(@ajd, of, @sg)
1323
+ end
1324
+
1325
+ private :offset, :new_offset
1326
+
1327
+ # Return a new Date object that is +n+ days later than the
1328
+ # current one.
1329
+ #
1330
+ # +n+ may be a negative value, in which case the new Date
1331
+ # is earlier than the current one; however, #-() might be
1332
+ # more intuitive.
1333
+ #
1334
+ # If +n+ is not a Numeric, a TypeError will be thrown. In
1335
+ # particular, two Dates cannot be added to each other.
1336
+ def + (n)
1337
+ case n
1338
+ when Numeric; return self.class.new!(@ajd + n, @of, @sg)
1339
+ end
1340
+ raise TypeError, 'expected numeric'
1341
+ end
1342
+
1343
+ # If +x+ is a Numeric value, create a new Date object that is
1344
+ # +x+ days earlier than the current one.
1345
+ #
1346
+ # If +x+ is a Date, return the number of days between the
1347
+ # two dates; or, more precisely, how many days later the current
1348
+ # date is than +x+.
1349
+ #
1350
+ # If +x+ is neither Numeric nor a Date, a TypeError is raised.
1351
+ def - (x)
1352
+ case x
1353
+ when Numeric; return self.class.new!(@ajd - x, @of, @sg)
1354
+ when Date; return @ajd - x.ajd
1355
+ end
1356
+ raise TypeError, 'expected numeric or date'
1357
+ end
1358
+
1359
+ # Compare this date with another date.
1360
+ #
1361
+ # +other+ can also be a Numeric value, in which case it is
1362
+ # interpreted as an Astronomical Julian Day Number.
1363
+ #
1364
+ # Comparison is by Astronomical Julian Day Number, including
1365
+ # fractional days. This means that both the time and the
1366
+ # timezone offset are taken into account when comparing
1367
+ # two DateTime instances. When comparing a DateTime instance
1368
+ # with a Date instance, the time of the latter will be
1369
+ # considered as falling on midnight UTC.
1370
+ def <=> (other)
1371
+ case other
1372
+ when Numeric; return @ajd <=> other
1373
+ when Date; return @ajd <=> other.ajd
1374
+ end
1375
+ nil
1376
+ end
1377
+
1378
+ # The relationship operator for Date.
1379
+ #
1380
+ # Compares dates by Julian Day Number. When comparing
1381
+ # two DateTime instances, or a DateTime with a Date,
1382
+ # the instances will be regarded as equivalent if they
1383
+ # fall on the same date in local time.
1384
+ def === (other)
1385
+ case other
1386
+ when Numeric; return jd == other
1387
+ when Date; return jd == other.jd
1388
+ end
1389
+ false
1390
+ end
1391
+
1392
+ def next_day(n=1) self + n end
1393
+ def prev_day(n=1) self - n end
1394
+
1395
+ # Return a new Date one day after this one.
1396
+ def next() next_day end
1397
+
1398
+ alias_method :succ, :next
1399
+
1400
+ # Return a new Date object that is +n+ months later than
1401
+ # the current one.
1402
+ #
1403
+ # If the day-of-the-month of the current Date is greater
1404
+ # than the last day of the target month, the day-of-the-month
1405
+ # of the returned Date will be the last day of the target month.
1406
+ def >> (n)
1407
+ y, m = (year * 12 + (mon - 1) + n).divmod(12)
1408
+ m, = (m + 1) .divmod(1)
1409
+ d = mday
1410
+ d -= 1 until jd2 = _valid_civil?(y, m, d, @sg)
1411
+ self + (jd2 - jd)
1412
+ end
1413
+
1414
+ # Return a new Date object that is +n+ months earlier than
1415
+ # the current one.
1416
+ #
1417
+ # If the day-of-the-month of the current Date is greater
1418
+ # than the last day of the target month, the day-of-the-month
1419
+ # of the returned Date will be the last day of the target month.
1420
+ def << (n) self >> -n end
1421
+
1422
+ def next_month(n=1) self >> n end
1423
+ def prev_month(n=1) self << n end
1424
+
1425
+ def next_year(n=1) self >> n * 12 end
1426
+ def prev_year(n=1) self << n * 12 end
1427
+
1428
+ require 'enumerator'
1429
+
1430
+ # Step the current date forward +step+ days at a
1431
+ # time (or backward, if +step+ is negative) until
1432
+ # we reach +limit+ (inclusive), yielding the resultant
1433
+ # date at each step.
1434
+ def step(limit, step=1) # :yield: date
1435
+ =begin
1436
+ if step.zero?
1437
+ raise ArgumentError, "step can't be 0"
1438
+ end
1439
+ =end
1440
+ unless block_given?
1441
+ return to_enum(:step, limit, step)
1442
+ end
1443
+ da = self
1444
+ op = %w(- <= >=)[step <=> 0]
1445
+ while da.__send__(op, limit)
1446
+ yield da
1447
+ da += step
1448
+ end
1449
+ self
1450
+ end
1451
+
1452
+ # Step forward one day at a time until we reach +max+
1453
+ # (inclusive), yielding each date as we go.
1454
+ def upto(max, &block) # :yield: date
1455
+ step(max, +1, &block)
1456
+ end
1457
+
1458
+ # Step backward one day at a time until we reach +min+
1459
+ # (inclusive), yielding each date as we go.
1460
+ def downto(min, &block) # :yield: date
1461
+ step(min, -1, &block)
1462
+ end
1463
+
1464
+ # Is this Date equal to +other+?
1465
+ #
1466
+ # +other+ must both be a Date object, and represent the same date.
1467
+ def eql? (other) Date === other && self == other end
1468
+
1469
+ # Calculate a hash value for this date.
1470
+ def hash() @ajd.hash end
1471
+
1472
+ # Return internal object state as a programmer-readable string.
1473
+ def inspect
1474
+ format('#<%s: %s (%s,%s,%s)>', self.class, to_s, @ajd, @of, @sg)
1475
+ end
1476
+
1477
+ # Return the date as a human-readable string.
1478
+ #
1479
+ # The format used is YYYY-MM-DD.
1480
+ def to_s() format('%.4d-%02d-%02d', year, mon, mday) end # 4p
1481
+
1482
+ # Dump to Marshal format.
1483
+ def marshal_dump() [@ajd, @of, @sg] end
1484
+
1485
+ # Load from Marshal format.
1486
+ def marshal_load(a)
1487
+ @ajd, @of, @sg, = a
1488
+ @__ca__ = {}
1489
+ end
1490
+
1491
+ end
1492
+
1493
+ # Class representing a date and time.
1494
+ #
1495
+ # See the documentation to the file date.rb for an overview.
1496
+ #
1497
+ # DateTime objects are immutable once created.
1498
+ #
1499
+ # == Other methods.
1500
+ #
1501
+ # The following methods are defined in Date, but declared private
1502
+ # there. They are made public in DateTime. They are documented
1503
+ # here.
1504
+ #
1505
+ # === hour()
1506
+ #
1507
+ # Get the hour-of-the-day of the time. This is given
1508
+ # using the 24-hour clock, counting from midnight. The first
1509
+ # hour after midnight is hour 0; the last hour of the day is
1510
+ # hour 23.
1511
+ #
1512
+ # === min()
1513
+ #
1514
+ # Get the minute-of-the-hour of the time.
1515
+ #
1516
+ # === sec()
1517
+ #
1518
+ # Get the second-of-the-minute of the time.
1519
+ #
1520
+ # === sec_fraction()
1521
+ #
1522
+ # Get the fraction of a second of the time. This is returned as
1523
+ # a +Rational+.
1524
+ #
1525
+ # === zone()
1526
+ #
1527
+ # Get the time zone as a String. This is representation of the
1528
+ # time offset such as "+1000", not the true time-zone name.
1529
+ #
1530
+ # === offset()
1531
+ #
1532
+ # Get the time zone offset as a fraction of a day. This is returned
1533
+ # as a +Rational+.
1534
+ #
1535
+ # === new_offset(of=0)
1536
+ #
1537
+ # Create a new DateTime object, identical to the current one, except
1538
+ # with a new time zone offset of +of+. +of+ is the new offset from
1539
+ # UTC as a fraction of a day.
1540
+ #
1541
+ class DateTime < Date
1542
+
1543
+ # Create a new DateTime object corresponding to the specified
1544
+ # Julian Day Number +jd+ and hour +h+, minute +min+, second +s+.
1545
+ #
1546
+ # The 24-hour clock is used. Negative values of +h+, +min+, and
1547
+ # +sec+ are treating as counting backwards from the end of the
1548
+ # next larger unit (e.g. a +min+ of -2 is treated as 58). No
1549
+ # wraparound is performed. If an invalid time portion is specified,
1550
+ # an ArgumentError is raised.
1551
+ #
1552
+ # +of+ is the offset from UTC as a fraction of a day (defaults to 0).
1553
+ # +sg+ specifies the Day of Calendar Reform.
1554
+ #
1555
+ # All day/time values default to 0.
1556
+ def self.jd(jd=0, h=0, min=0, s=0, of=0, sg=ITALY)
1557
+ unless (jd = _valid_jd?(jd, sg)) &&
1558
+ (fr = _valid_time?(h, min, s))
1559
+ raise ArgumentError, 'invalid date'
1560
+ end
1561
+ if String === of
1562
+ of = Rational(zone_to_diff(of) || 0, 86400)
1563
+ end
1564
+ new!(jd_to_ajd(jd, fr, of), of, sg)
1565
+ end
1566
+
1567
+ # Create a new DateTime object corresponding to the specified
1568
+ # Ordinal Date and hour +h+, minute +min+, second +s+.
1569
+ #
1570
+ # The 24-hour clock is used. Negative values of +h+, +min+, and
1571
+ # +sec+ are treating as counting backwards from the end of the
1572
+ # next larger unit (e.g. a +min+ of -2 is treated as 58). No
1573
+ # wraparound is performed. If an invalid time portion is specified,
1574
+ # an ArgumentError is raised.
1575
+ #
1576
+ # +of+ is the offset from UTC as a fraction of a day (defaults to 0).
1577
+ # +sg+ specifies the Day of Calendar Reform.
1578
+ #
1579
+ # +y+ defaults to -4712, and +d+ to 1; this is Julian Day Number
1580
+ # day 0. The time values default to 0.
1581
+ def self.ordinal(y=-4712, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
1582
+ unless (jd = _valid_ordinal?(y, d, sg)) &&
1583
+ (fr = _valid_time?(h, min, s))
1584
+ raise ArgumentError, 'invalid date'
1585
+ end
1586
+ if String === of
1587
+ of = Rational(zone_to_diff(of) || 0, 86400)
1588
+ end
1589
+ new!(jd_to_ajd(jd, fr, of), of, sg)
1590
+ end
1591
+
1592
+ # Create a new DateTime object corresponding to the specified
1593
+ # Civil Date and hour +h+, minute +min+, second +s+.
1594
+ #
1595
+ # The 24-hour clock is used. Negative values of +h+, +min+, and
1596
+ # +sec+ are treating as counting backwards from the end of the
1597
+ # next larger unit (e.g. a +min+ of -2 is treated as 58). No
1598
+ # wraparound is performed. If an invalid time portion is specified,
1599
+ # an ArgumentError is raised.
1600
+ #
1601
+ # +of+ is the offset from UTC as a fraction of a day (defaults to 0).
1602
+ # +sg+ specifies the Day of Calendar Reform.
1603
+ #
1604
+ # +y+ defaults to -4712, +m+ to 1, and +d+ to 1; this is Julian Day
1605
+ # Number day 0. The time values default to 0.
1606
+ def self.civil(y=-4712, m=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
1607
+ unless (jd = _valid_civil?(y, m, d, sg)) &&
1608
+ (fr = _valid_time?(h, min, s))
1609
+ raise ArgumentError, 'invalid date'
1610
+ end
1611
+ if String === of
1612
+ of = Rational(zone_to_diff(of) || 0, 86400)
1613
+ end
1614
+ new!(jd_to_ajd(jd, fr, of), of, sg)
1615
+ end
1616
+
1617
+ class << self; alias_method :new, :civil end
1618
+
1619
+ # Create a new DateTime object corresponding to the specified
1620
+ # Commercial Date and hour +h+, minute +min+, second +s+.
1621
+ #
1622
+ # The 24-hour clock is used. Negative values of +h+, +min+, and
1623
+ # +sec+ are treating as counting backwards from the end of the
1624
+ # next larger unit (e.g. a +min+ of -2 is treated as 58). No
1625
+ # wraparound is performed. If an invalid time portion is specified,
1626
+ # an ArgumentError is raised.
1627
+ #
1628
+ # +of+ is the offset from UTC as a fraction of a day (defaults to 0).
1629
+ # +sg+ specifies the Day of Calendar Reform.
1630
+ #
1631
+ # +y+ defaults to -4712, +w+ to 1, and +d+ to 1; this is
1632
+ # Julian Day Number day 0.
1633
+ # The time values default to 0.
1634
+ def self.commercial(y=-4712, w=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
1635
+ unless (jd = _valid_commercial?(y, w, d, sg)) &&
1636
+ (fr = _valid_time?(h, min, s))
1637
+ raise ArgumentError, 'invalid date'
1638
+ end
1639
+ if String === of
1640
+ of = Rational(zone_to_diff(of) || 0, 86400)
1641
+ end
1642
+ new!(jd_to_ajd(jd, fr, of), of, sg)
1643
+ end
1644
+
1645
+ def self.weeknum(y=-4712, w=0, d=1, f=0, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc:
1646
+ unless (jd = _valid_weeknum?(y, w, d, f, sg)) &&
1647
+ (fr = _valid_time?(h, min, s))
1648
+ raise ArgumentError, 'invalid date'
1649
+ end
1650
+ if String === of
1651
+ of = Rational(zone_to_diff(of) || 0, 86400)
1652
+ end
1653
+ new!(jd_to_ajd(jd, fr, of), of, sg)
1654
+ end
1655
+
1656
+ private_class_method :weeknum
1657
+
1658
+ def self.nth_kday(y=-4712, m=1, n=1, k=1, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc:
1659
+ unless (jd = _valid_nth_kday?(y, m, n, k, sg)) &&
1660
+ (fr = _valid_time?(h, min, s))
1661
+ raise ArgumentError, 'invalid date'
1662
+ end
1663
+ if String === of
1664
+ of = Rational(zone_to_diff(of) || 0, 86400)
1665
+ end
1666
+ new!(jd_to_ajd(jd, fr, of), of, sg)
1667
+ end
1668
+
1669
+ private_class_method :nth_kday
1670
+
1671
+ def self.new_by_frags(elem, sg) # :nodoc:
1672
+ elem = rewrite_frags(elem)
1673
+ elem = complete_frags(elem)
1674
+ unless (jd = valid_date_frags?(elem, sg)) &&
1675
+ (fr = valid_time_frags?(elem))
1676
+ raise ArgumentError, 'invalid date'
1677
+ end
1678
+ fr += (elem[:sec_fraction] || 0) / 86400
1679
+ of = Rational(elem[:offset] || 0, 86400)
1680
+ new!(jd_to_ajd(jd, fr, of), of, sg)
1681
+ end
1682
+
1683
+ private_class_method :new_by_frags
1684
+
1685
+ # Create a new DateTime object by parsing from a String
1686
+ # according to a specified format.
1687
+ #
1688
+ # +str+ is a String holding a date-time representation.
1689
+ # +fmt+ is the format that the date-time is in. See
1690
+ # date/format.rb for details on supported formats.
1691
+ #
1692
+ # The default +str+ is '-4712-01-01T00:00:00+00:00', and the default
1693
+ # +fmt+ is '%FT%T%z'. This gives midnight on Julian Day Number day 0.
1694
+ #
1695
+ # +sg+ specifies the Day of Calendar Reform.
1696
+ #
1697
+ # An ArgumentError will be raised if +str+ cannot be
1698
+ # parsed.
1699
+ def self.strptime(str='-4712-01-01T00:00:00+00:00', fmt='%FT%T%z', sg=ITALY)
1700
+ elem = _strptime(str, fmt)
1701
+ new_by_frags(elem, sg)
1702
+ end
1703
+
1704
+ # Create a new DateTime object by parsing from a String,
1705
+ # without specifying the format.
1706
+ #
1707
+ # +str+ is a String holding a date-time representation.
1708
+ # +comp+ specifies whether to interpret 2-digit years
1709
+ # as 19XX (>= 69) or 20XX (< 69); the default is not to.
1710
+ # The method will attempt to parse a date-time from the String
1711
+ # using various heuristics; see #_parse in date/format.rb
1712
+ # for more details. If parsing fails, an ArgumentError
1713
+ # will be raised.
1714
+ #
1715
+ # The default +str+ is '-4712-01-01T00:00:00+00:00'; this is Julian
1716
+ # Day Number day 0.
1717
+ #
1718
+ # +sg+ specifies the Day of Calendar Reform.
1719
+ def self.parse(str='-4712-01-01T00:00:00+00:00', comp=true, sg=ITALY)
1720
+ elem = _parse(str, comp)
1721
+ new_by_frags(elem, sg)
1722
+ end
1723
+
1724
+ def self.iso8601(str='-4712-01-01T00:00:00+00:00', sg=ITALY) # :nodoc:
1725
+ elem = _iso8601(str)
1726
+ new_by_frags(elem, sg)
1727
+ end
1728
+
1729
+ def self.rfc3339(str='-4712-01-01T00:00:00+00:00', sg=ITALY) # :nodoc:
1730
+ elem = _rfc3339(str)
1731
+ new_by_frags(elem, sg)
1732
+ end
1733
+
1734
+ def self.xmlschema(str='-4712-01-01T00:00:00+00:00', sg=ITALY) # :nodoc:
1735
+ elem = _xmlschema(str)
1736
+ new_by_frags(elem, sg)
1737
+ end
1738
+
1739
+ def self.rfc2822(str='Mon, 1 Jan -4712 00:00:00 +0000', sg=ITALY) # :nodoc:
1740
+ elem = _rfc2822(str)
1741
+ new_by_frags(elem, sg)
1742
+ end
1743
+
1744
+ class << self; alias_method :rfc822, :rfc2822 end
1745
+
1746
+ def self.httpdate(str='Mon, 01 Jan -4712 00:00:00 GMT', sg=ITALY) # :nodoc:
1747
+ elem = _httpdate(str)
1748
+ new_by_frags(elem, sg)
1749
+ end
1750
+
1751
+ def self.jisx0301(str='-4712-01-01T00:00:00+00:00', sg=ITALY) # :nodoc:
1752
+ elem = _jisx0301(str)
1753
+ new_by_frags(elem, sg)
1754
+ end
1755
+
1756
+ public :hour, :min, :sec, :sec_fraction, :zone, :offset, :new_offset,
1757
+ :minute, :second, :second_fraction
1758
+
1759
+ def to_s # 4p
1760
+ format('%.4d-%02d-%02dT%02d:%02d:%02d%s',
1761
+ year, mon, mday, hour, min, sec, zone)
1762
+ end
1763
+
1764
+ end
1765
+
1766
+ class Time
1767
+
1768
+ def to_time() getlocal end
1769
+
1770
+ def to_date
1771
+ jd = Date.__send__(:civil_to_jd, year, mon, mday, Date::ITALY)
1772
+ Date.new!(Date.__send__(:jd_to_ajd, jd, 0, 0), 0, Date::ITALY)
1773
+ end
1774
+
1775
+ def to_datetime
1776
+ jd = DateTime.__send__(:civil_to_jd, year, mon, mday, DateTime::ITALY)
1777
+ fr = DateTime.__send__(:time_to_day_fraction, hour, min, [sec, 59].min) +
1778
+ Rational(nsec, 86400_000_000_000)
1779
+ of = Rational(utc_offset, 86400)
1780
+ DateTime.new!(DateTime.__send__(:jd_to_ajd, jd, fr, of),
1781
+ of, DateTime::ITALY)
1782
+ end
1783
+
1784
+ end
1785
+
1786
+ class Date
1787
+
1788
+ def to_time() Time.local(year, mon, mday) end
1789
+ def to_date() self end
1790
+ def to_datetime() DateTime.new!(jd_to_ajd(jd, 0, 0), @of, @sg) end
1791
+
1792
+ # Create a new Date object representing today.
1793
+ #
1794
+ # +sg+ specifies the Day of Calendar Reform.
1795
+ def self.today(sg=ITALY)
1796
+ t = Time.now
1797
+ jd = civil_to_jd(t.year, t.mon, t.mday, sg)
1798
+ new!(jd_to_ajd(jd, 0, 0), 0, sg)
1799
+ end
1800
+
1801
+ # Create a new DateTime object representing the current time.
1802
+ #
1803
+ # +sg+ specifies the Day of Calendar Reform.
1804
+ def self.now(sg=ITALY)
1805
+ t = Time.now
1806
+ jd = civil_to_jd(t.year, t.mon, t.mday, sg)
1807
+ fr = time_to_day_fraction(t.hour, t.min, [t.sec, 59].min) +
1808
+ Rational(t.nsec, 86400_000_000_000)
1809
+ of = Rational(t.utc_offset, 86400)
1810
+ new!(jd_to_ajd(jd, fr, of), of, sg)
1811
+ end
1812
+
1813
+ private_class_method :now
1814
+
1815
+ end
1816
+
1817
+ class DateTime < Date
1818
+
1819
+ def to_time
1820
+ d = new_offset(0)
1821
+ d.instance_eval do
1822
+ Time.utc(year, mon, mday, hour, min, sec +
1823
+ sec_fraction)
1824
+ end.
1825
+ getlocal
1826
+ end
1827
+
1828
+ def to_date() Date.new!(jd_to_ajd(jd, 0, 0), 0, @sg) end
1829
+ def to_datetime() self end
1830
+
1831
+ private_class_method :today
1832
+ public_class_method :now
1833
+
1834
+ end