~ubuntu-branches/ubuntu/saucy/ruby-facets/saucy

« back to all changes in this revision

Viewing changes to src/core/facets/time/change.rb

  • Committer: Package Import Robot
  • Author(s): Marc Dequènes (Duck)
  • Date: 2013-06-21 14:41:38 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130621144138-nb3t82yl5gl8p7a6
Tags: 2.9.3-1
* New upstream release:
  - rakefile is gone, switched back to setuprb method
  - recreated documention build rules and adapted to new paths
* Updated copyright file.
* Increased Standards-Version to 3.9.4 (no changes).
* Removed transitional libfacets-* package and obsolete relations.
* Use system JQuery library instead of embedded one for documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
class Time
2
 
 
3
 
  # Returns a new Time where one or more of the elements
4
 
  # have been changed according to the +options+ parameter.
5
 
  # The time options (hour, minute, sec, usec) reset
6
 
  # cascadingly, so if only the hour is passed, then
7
 
  # minute, sec, and usec is set to 0. If the hour and
8
 
  # minute is passed, then sec and usec is set to 0.
9
 
  #
10
 
  #   t1 = Time.at(10000)
11
 
  #   t1.ctime   #=> "Wed Dec 31 21:46:40 1969"
12
 
  #
13
 
  #   t2 = t1.change(:hour => 11)
14
 
  #   t2.ctime   #=> "Wed Dec 31 11:00:00 1969"
15
 
  #
16
 
  def change(options)
17
 
    opts=options; #{}; options.each_pair{ |k,v| opts[k] = v.to_i }
18
 
    self.class.send(
19
 
      self.utc? ? :utc : :local,
20
 
      opts[:year]  || self.year,
21
 
      opts[:month] || self.month,
22
 
      opts[:day]   || self.day,
23
 
      opts[:hour]  || self.hour,
24
 
      opts[:min]   || (opts[:hour] ? 0 : self.min),
25
 
      opts[:sec]   || ((opts[:hour] || opts[:min]) ? 0 : self.sec),
26
 
      opts[:usec]  || ((opts[:hour] || opts[:min] || opts[:sec]) ? 0 : self.usec)
27
 
    )
28
 
  end
29
 
 
30
 
  # Old Version ...
31
 
  #
32
 
  #   def change(options)
33
 
  #     ::Time.send(
34
 
  #       self.utc? ? :utc_time : :local_time,
35
 
  #       options[:year]  || self.year,
36
 
  #       options[:month] || self.month,
37
 
  #       options[:day]   || self.day,
38
 
  #       options[:hour]  || self.hour,
39
 
  #       options[:min]   || (options[:hour] ? 0 : self.min),
40
 
  #       options[:sec]   || ((options[:hour] || options[:min]) ? 0 : self.sec),
41
 
  #       options[:usec]  || ((options[:hour] || options[:min] || options[:sec]) ? 0 : self.usec)
42
 
  #     )
43
 
  #  end
44
 
 
45
 
end
46