File: jroku.rb

package info (click to toggle)
tdiary-contrib 5.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,772 kB
  • sloc: ruby: 17,305; javascript: 8,263; lisp: 562; xml: 451; php: 61; sql: 40; makefile: 18
file content (28 lines) | stat: -rw-r--r-- 952 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# jroku.rb $Revision: 1.1 $
#
#「%R」で六曜を出す
#    動かすためには
#    http://www.funaba.org/calendar.html#calendar
#    で配布されているClendarモジュールと付属しているcalclass.rbが必要
#    日付フォーマットなどで「%R」を指定するとそこが六曜になる
#
# Copyright (c) 2005 SHIBATA Hiroshi <h-sbt@nifty.com>
# You can distribute this file under the GPL.
#
require 'calclass.rb'

unless Time::new.respond_to?( :strftime_jroku_backup ) then
   eval( <<-MODIFY_CLASS, TOPLEVEL_BINDING )
   class Time
      alias strftime_jroku_backup strftime
      JROKU = %w(大安 赤口 先勝 友引 先負 仏滅)

      def strftime( format )
         d=Gregorian.new(self.month, self.day, self.year)
         q_d = Calendar.kyureki_from_absolute(d.abs)
         index = (q_d[0] + q_d[2]) % 6
         strftime_jroku_backup( format.gsub( /%R/, JROKU[index] ) )
      end
   end
   MODIFY_CLASS
end