lib/fugit/cron.rb in fugit-1.5.2 vs lib/fugit/cron.rb in fugit-1.5.3

- old
+ new

@@ -58,11 +58,11 @@ @seconds == [ 0 ] ? nil : (@seconds || [ '*' ]).join(','), (@minutes || [ '*' ]).join(','), (@hours || [ '*' ]).join(','), (@monthdays || [ '*' ]).join(','), (@months || [ '*' ]).join(','), - (@weekdays || [ [ '*' ] ]).map { |d| d.compact.join('#') }.join(','), + weekdays_to_cron_s, @timezone ? @timezone.name : nil ].compact.join(' ') end class TimeCursor @@ -72,10 +72,12 @@ @t = t.is_a?(TimeCursor) ? t.time : t @t.seconds = @t.seconds.to_i end def time; @t; end + def to_t; @t; end + # def to_i; @t.to_i; end %w[ year month day wday hour min sec wday_in_month rweek rday ] .collect(&:to_sym).each { |k| define_method(k) { @t.send(k) } } @@ -616,9 +618,27 @@ end def determine_timezone(z) @zone, @timezone = z + end + + def weekdays_to_cron_s + + return '*' unless @weekdays + + @weekdays + .collect { |a| + if a.length == 1 + a[0].to_s + elsif a[1].is_a?(Array) + a11 = a[1][1] + off = (a11 < 0) ? a11.to_s : (a11 > 0) ? "+#{a11}" : '' + "#{a[0]}%#{a[1][0]}" + off + else + a.collect(&:to_s).join('#') + end } + .join(',') end module Parser include Raabro WEEKDAYS =