Slide 1

Slide 1 text

*OTJEFBOEBSPVOE
 "DUJWF4VQQPSU%VSBUJPO 8BOUFEMZ&OHJOFFS ,FOUP/BHBUB

Slide 2

Slide 2 text

w 7JJCBS w 8FC ಈը੍࡞ࢧԉπʔϧ։ൃ w 8BOUFEMZ w 8FC 8BOUFEMZ5PPMT 8BOUFEMZ7JTJU6TFS(SPXUI Ӭా݈ਓ !OHUL

Slide 3

Slide 3 text

ࠓ೔࿩͢͜ͱ

Slide 4

Slide 4 text

"DUJWF4VQQPSU%VSBUJPOͱ೔෇ԋࢉ
 ʹ͍ͭͯ

Slide 5

Slide 5 text

ͳͥ"DUJWF4VQQPSU%VSBUJPOͷ࿩
 Λ͢Δͷ͔

Slide 6

Slide 6 text

"DUJWF4VQQPSU%VSBUJPO͕޷͖͔ͩΒ

Slide 7

Slide 7 text

3VCZͱ3BJMTΛ࢝Ίͨͱ͖ʹ
 ײಈͨ͠ॻ͖ํ

Slide 8

Slide 8 text

EBZTBHP

Slide 9

Slide 9 text

ࣗવݴޠͬΆ͘ॻ͚ͯ௚ײత✨

Slide 10

Slide 10 text

"DUJWF4VQQPSUͱ͸ʁ

Slide 11

Slide 11 text

༷ʑͳϢʔςΟϦςΟʔΫϥεͱίΞ֦ு

Slide 12

Slide 12 text

$PSF&YU )BTI $MBTT %BUF %BUF5JNF 'JMF 'MPBU *OUFHFS ,FSOFM .PEVMF &OVNFSBCMF "SSBZ 4USJOH "VUPMPBE +40/ $BDIF /PUJpDBUJPOT "DUJWF4VQQPSU $POpHVSBCMF $PODFSO 5JNF;POF 9NM.JOJ ,FZ(FOFSBUPS -PHHFS 0SEFSFE)BTI 0SEFSFE0QUJPOT 3FTDVBCMF 4FDVSJUZ6UJMT 5JNF8JUI;POF .FTTBHF7FSJpFS .FTTBHF&ODSZQUPS $BMMCBDLT "SSBZ*ORVJSFS 4USJOH*ORVJSFS %VSBUJPO

Slide 13

Slide 13 text

$PSF&YU )BTI $MBTT %BUF %BUF5JNF 'JMF 'MPBU *OUFHFS ,FSOFM .PEVMF &OVNFSBCMF "SSBZ 4USJOH "VUPMPBE +40/ $BDIF /PUJpDBUJPOT "DUJWF4VQQPSU $POpHVSBCMF $PODFSO 5JNF;POF 9NM.JOJ ,FZ(FOFSBUPS -PHHFS 0SEFSFE)BTI 0SEFSFE0QUJPOT 3FTDVBCMF 4FDVSJUZ6UJMT 5JNF8JUI;POF .FTTBHF7FSJpFS .FTTBHF&ODSZQUPS $BMMCBDLT "SSBZ*ORVJSFS 4USJOH*ORVJSFS %VSBUJPO /VNFSJD

Slide 14

Slide 14 text

NPOUI͜Ε͕%VSBUJPO

Slide 15

Slide 15 text

w XFFLTBHPΛͨ͠ͱ͖ʹԿ͕ى͖͍ͯΔͷ͔Λ௥͍͖ͬͯͳ͕Β %VSBUJPOΫϥεͷ࣮૷Λ௥͍·͢ w όʔδϣϯ͸Ͱ͢

Slide 16

Slide 16 text

XFFLTBHP

Slide 17

Slide 17 text

XFFLTBHP *OUFHFS

Slide 18

Slide 18 text

XFFLTBHP /VNFSJDXFFLT

Slide 19

Slide 19 text

XFFLTBHP 'MPBU

Slide 20

Slide 20 text

w TFDPOET NJOVUFT IPVST EBZT XFFLTϝιου͸/VNFSJDʹఆٛ w NPOUIT ZFBSTϝιου͸*OUFHFSʹఆٛ

Slide 21

Slide 21 text

݄ͱ೥ͷ௕͞͸Ұఆ͍ͯ͠ͳ͍ʂ

Slide 22

Slide 22 text

ྫ͑͹ϲ݄ͱ͔ΛऔΓѻ͏ͷ ͸೉͍͋͠͠·Γҙຯ͕ͳ͍

Slide 23

Slide 23 text

class Integer def months ActiveSupport::Duration.months(self) end alias :month :months def years ActiveSupport::Duration.years(self) end alias :year :years end

Slide 24

Slide 24 text

class Numeric def seconds ActiveSupport::Duration.seconds(self) end alias :second :seconds def minutes ActiveSupport::Duration.minutes(self) end alias :minute :minutes def hours ActiveSupport::Duration.hours(self) end alias :hour :hours def days ActiveSupport::Duration.days(self) end alias :day :days def weeks ActiveSupport::Duration.weeks(self) end alias :week :weeks end

Slide 25

Slide 25 text

class Numeric def weeks ActiveSupport::Duration.weeks(self) end alias :week :weeks end

Slide 26

Slide 26 text

class Numeric def weeks ActiveSupport::Duration.weeks(self) end alias :week :weeks end

Slide 27

Slide 27 text

module ActiveSupport class Duration SECONDS_PER_MINUTE = 60 SECONDS_PER_HOUR = 3600 SECONDS_PER_DAY = 86400 SECONDS_PER_WEEK = 604800 SECONDS_PER_MONTH = 2629746 # 1/12 of a gregorian year SECONDS_PER_YEAR = 31556952 # length of a gregorian year (365.2425 days) class << self def weeks(value) new(value * SECONDS_PER_WEEK, [[:weeks, value]]) end end def initialize(value, parts) @value, @parts = value, parts.to_h @parts.default = 0 end end end

Slide 28

Slide 28 text

module ActiveSupport class Duration SECONDS_PER_MINUTE = 60 SECONDS_PER_HOUR = 3600 SECONDS_PER_DAY = 86400 SECONDS_PER_WEEK = 604800 SECONDS_PER_MONTH = 2629746 # 1/12 of a gregorian year SECONDS_PER_YEAR = 31556952 # length of a gregorian year (365.2425 days) class << self def weeks(value) new(value * SECONDS_PER_WEEK, [[:weeks, value]]) end end def initialize(value, parts) @value, @parts = value, parts.to_h @parts.default = 0 end end end

Slide 29

Slide 29 text

module ActiveSupport class Duration SECONDS_PER_MINUTE = 60 SECONDS_PER_HOUR = 3600 SECONDS_PER_DAY = 86400 SECONDS_PER_WEEK = 604800 SECONDS_PER_MONTH = 2629746 # 1/12 of a gregorian year SECONDS_PER_YEAR = 31556952 # length of a gregorian year (365.2425 days) class << self def weeks(value) new(value * SECONDS_PER_WEEK, [[:weeks, value]]) end end def initialize(value, parts) @value, @parts = value, parts.to_h @parts.default = 0 end end end

Slide 30

Slide 30 text

module ActiveSupport class Duration SECONDS_PER_MINUTE = 60 SECONDS_PER_HOUR = 3600 SECONDS_PER_DAY = 86400 SECONDS_PER_WEEK = 604800 SECONDS_PER_MONTH = 2629746 # 1/12 of a gregorian year SECONDS_PER_YEAR = 31556952 # length of a gregorian year (365.2425 days) class << self def weeks(value) new(value * SECONDS_PER_WEEK, [[:weeks, value]]) end end def initialize(value, parts) @value, @parts = value, parts.to_h @parts.default = 0 end end end ඵ਺ ֤୯Ґͱ஋ͷ૊Έ߹Θͤ

Slide 31

Slide 31 text

module ActiveSupport class Duration SECONDS_PER_MINUTE = 60 SECONDS_PER_HOUR = 3600 SECONDS_PER_DAY = 86400 SECONDS_PER_WEEK = 604800 SECONDS_PER_MONTH = 2629746 # 1/12 of a gregorian year SECONDS_PER_YEAR = 31556952 # length of a gregorian year (365.2425 days) class << self def weeks(value) new(value * SECONDS_PER_WEEK, [[:weeks, value]]) end end def initialize(value, parts) @value, @parts = value, parts.to_h @parts.default = 0 end end end ඵ਺ ֤୯Ґͱ஋ͷ૊Έ߹Θͤ \XFFLT^

Slide 32

Slide 32 text

module ActiveSupport class Duration SECONDS_PER_MINUTE = 60 SECONDS_PER_HOUR = 3600 SECONDS_PER_DAY = 86400 SECONDS_PER_WEEK = 604800 SECONDS_PER_MONTH = 2629746 # 1/12 of a gregorian year SECONDS_PER_YEAR = 31556952 # length of a gregorian year (365.2425 days) class << self def seconds(value) new(value, [[:seconds, value]]) end def minutes(value) new(value * SECONDS_PER_MINUTE, [[:minutes, value]]) end def hours(value) new(value * SECONDS_PER_HOUR, [[:hours, value]]) end def days(value) new(value * SECONDS_PER_DAY, [[:days, value]]) end def weeks(value) new(value * SECONDS_PER_WEEK, [[:weeks, value]]) end def months(value) new(value * SECONDS_PER_MONTH, [[:months, value]]) end def years(value) new(value * SECONDS_PER_YEAR, [[:years, value]]) end end end end

Slide 33

Slide 33 text

XFFLTBHP %VSBUJPO XFFLTWBMVF XFFLTQBSUT\XFFLT^

Slide 34

Slide 34 text

module ActiveSupport class Duration def ago(time = ::Time.current) sum(-1, time) end alias :until :ago alias :before :ago end end

Slide 35

Slide 35 text

module ActiveSupport class Duration private def sum(sign, time = ::Time.current) parts.inject(time) do |t, (type, number)| if t.acts_like?(:time) || t.acts_like?(:date) if type == :seconds t.since(sign * number) elsif type == :minutes t.since(sign * number * 60) elsif type == :hours t.since(sign * number * 3600) else t.advance(type => sign * number) end else raise ::ArgumentError, "expected a time or date, got #{time.inspect}" end end end end end

Slide 36

Slide 36 text

module ActiveSupport class Duration private def sum(sign, time = ::Time.current) parts.inject(time) do |t, (type, number)| if t.acts_like?(:time) || t.acts_like?(:date) if type == :seconds t.since(sign * number) elsif type == :minutes t.since(sign * number * 60) elsif type == :hours t.since(sign * number * 3600) else t.advance(type => sign * number) end else raise ::ArgumentError, "expected a time or date, got #{time.inspect}" end end end end end \XFFLT^

Slide 37

Slide 37 text

module ActiveSupport class Duration private def sum(sign, time = ::Time.current) parts.inject(time) do |t, (type, number)| if t.acts_like?(:time) || t.acts_like?(:date) if type == :seconds t.since(sign * number) elsif type == :minutes t.since(sign * number * 60) elsif type == :hours t.since(sign * number * 3600) else t.advance(type => sign * number) end else raise ::ArgumentError, "expected a time or date, got #{time.inspect}" end end end end end XFFLT

Slide 38

Slide 38 text

module ActiveSupport class Duration private def sum(sign, time = ::Time.current) parts.inject(time) do |t, (type, number)| if t.acts_like?(:time) || t.acts_like?(:date) if type == :seconds t.since(sign * number) elsif type == :minutes t.since(sign * number * 60) elsif type == :hours t.since(sign * number * 3600) else t.advance(type => sign * number) end else raise ::ArgumentError, "expected a time or date, got #{time.inspect}" end end end end end

Slide 39

Slide 39 text

module ActiveSupport class Duration private def sum(sign, time = ::Time.current) parts.inject(time) do |t, (type, number)| if t.acts_like?(:time) || t.acts_like?(:date) if type == :seconds t.since(sign * number) elsif type == :minutes t.since(sign * number * 60) elsif type == :hours t.since(sign * number * 3600) else t.advance(type => sign * number) end else raise ::ArgumentError, "expected a time or date, got #{time.inspect}" end end end end end

Slide 40

Slide 40 text

module ActiveSupport class Duration private def sum(sign, time = ::Time.current) parts.inject(time) do |t, (type, number)| if t.acts_like?(:time) || t.acts_like?(:date) if type == :seconds t.since(sign * number) elsif type == :minutes t.since(sign * number * 60) elsif type == :hours t.since(sign * number * 3600) else t.advance(type => sign * number) end else raise ::ArgumentError, "expected a time or date, got #{time.inspect}" end end end end end XFFLT

Slide 41

Slide 41 text

class DateTime def advance(options) unless options[:weeks].nil? options[:weeks], partial_weeks = options[:weeks].divmod(1) options[:days] = options.fetch(:days, 0) + 7 * partial_weeks end unless options[:days].nil? options[:days], partial_days = options[:days].divmod(1) options[:hours] = options.fetch(:hours, 0) + 24 * partial_days end d = to_date.advance(options) datetime_advanced_by_date = change(year: d.year, month: d.month, day: d.day) seconds_to_advance = \ options.fetch(:seconds, 0) + options.fetch(:minutes, 0) * 60 + options.fetch(:hours, 0) * 3600 if seconds_to_advance.zero? datetime_advanced_by_date else datetime_advanced_by_date.since(seconds_to_advance) end end end

Slide 42

Slide 42 text

class DateTime def advance(options) unless options[:weeks].nil? options[:weeks], partial_weeks = options[:weeks].divmod(1) options[:days] = options.fetch(:days, 0) + 7 * partial_weeks end unless options[:days].nil? options[:days], partial_days = options[:days].divmod(1) options[:hours] = options.fetch(:hours, 0) + 24 * partial_days end d = to_date.advance(options) datetime_advanced_by_date = change(year: d.year, month: d.month, day: d.day) seconds_to_advance = \ options.fetch(:seconds, 0) + options.fetch(:minutes, 0) * 60 + options.fetch(:hours, 0) * 3600 if seconds_to_advance.zero? datetime_advanced_by_date else datetime_advanced_by_date.since(seconds_to_advance) end end end \XFFLT^

Slide 43

Slide 43 text

class DateTime def advance(options) unless options[:weeks].nil? options[:weeks], partial_weeks = options[:weeks].divmod(1) options[:days] = options.fetch(:days, 0) + 7 * partial_weeks end unless options[:days].nil? options[:days], partial_days = options[:days].divmod(1) options[:hours] = options.fetch(:hours, 0) + 24 * partial_days end d = to_date.advance(options) datetime_advanced_by_date = change(year: d.year, month: d.month, day: d.day) seconds_to_advance = \ options.fetch(:seconds, 0) + options.fetch(:minutes, 0) * 60 + options.fetch(:hours, 0) * 3600 if seconds_to_advance.zero? datetime_advanced_by_date else datetime_advanced_by_date.since(seconds_to_advance) end end end \XFFLT^ ༨Γ༗ΓͰׂΔ

Slide 44

Slide 44 text

class DateTime def advance(options) unless options[:weeks].nil? options[:weeks], partial_weeks = options[:weeks].divmod(1) options[:days] = options.fetch(:days, 0) + 7 * partial_weeks end unless options[:days].nil? options[:days], partial_days = options[:days].divmod(1) options[:hours] = options.fetch(:hours, 0) + 24 * partial_days end d = to_date.advance(options) datetime_advanced_by_date = change(year: d.year, month: d.month, day: d.day) seconds_to_advance = \ options.fetch(:seconds, 0) + options.fetch(:minutes, 0) * 60 + options.fetch(:hours, 0) * 3600 if seconds_to_advance.zero? datetime_advanced_by_date else datetime_advanced_by_date.since(seconds_to_advance) end end end \XFFLT^ ༨Γ

Slide 45

Slide 45 text

class DateTime def advance(options) unless options[:weeks].nil? options[:weeks], partial_weeks = options[:weeks].divmod(1) options[:days] = options.fetch(:days, 0) + 7 * partial_weeks end unless options[:days].nil? options[:days], partial_days = options[:days].divmod(1) options[:hours] = options.fetch(:hours, 0) + 24 * partial_days end d = to_date.advance(options) datetime_advanced_by_date = change(year: d.year, month: d.month, day: d.day) seconds_to_advance = \ options.fetch(:seconds, 0) + options.fetch(:minutes, 0) * 60 + options.fetch(:hours, 0) * 3600 if seconds_to_advance.zero? datetime_advanced_by_date else datetime_advanced_by_date.since(seconds_to_advance) end end end \XFFLT^ ༨Γ

Slide 46

Slide 46 text

class DateTime def advance(options) unless options[:weeks].nil? options[:weeks], partial_weeks = options[:weeks].divmod(1) options[:days] = options.fetch(:days, 0) + 7 * partial_weeks end unless options[:days].nil? options[:days], partial_days = options[:days].divmod(1) options[:hours] = options.fetch(:hours, 0) + 24 * partial_days end d = to_date.advance(options) datetime_advanced_by_date = change(year: d.year, month: d.month, day: d.day) seconds_to_advance = \ options.fetch(:seconds, 0) + options.fetch(:minutes, 0) * 60 + options.fetch(:hours, 0) * 3600 if seconds_to_advance.zero? datetime_advanced_by_date else datetime_advanced_by_date.since(seconds_to_advance) end end end \XFFLT^ ༨Γ

Slide 47

Slide 47 text

class DateTime def advance(options) unless options[:weeks].nil? options[:weeks], partial_weeks = options[:weeks].divmod(1) options[:days] = options.fetch(:days, 0) + 7 * partial_weeks end unless options[:days].nil? options[:days], partial_days = options[:days].divmod(1) options[:hours] = options.fetch(:hours, 0) + 24 * partial_days end d = to_date.advance(options) datetime_advanced_by_date = change(year: d.year, month: d.month, day: d.day) seconds_to_advance = \ options.fetch(:seconds, 0) + options.fetch(:minutes, 0) * 60 + options.fetch(:hours, 0) * 3600 if seconds_to_advance.zero? datetime_advanced_by_date else datetime_advanced_by_date.since(seconds_to_advance) end end end \XFFLT^

Slide 48

Slide 48 text

class DateTime def advance(options) unless options[:weeks].nil? options[:weeks], partial_weeks = options[:weeks].divmod(1) options[:days] = options.fetch(:days, 0) + 7 * partial_weeks end unless options[:days].nil? options[:days], partial_days = options[:days].divmod(1) options[:hours] = options.fetch(:hours, 0) + 24 * partial_days end d = to_date.advance(options) datetime_advanced_by_date = change(year: d.year, month: d.month, day: d.day) seconds_to_advance = \ options.fetch(:seconds, 0) + options.fetch(:minutes, 0) * 60 + options.fetch(:hours, 0) * 3600 if seconds_to_advance.zero? datetime_advanced_by_date else datetime_advanced_by_date.since(seconds_to_advance) end end end \XFFLT^ \XFFLT^

Slide 49

Slide 49 text

class Date def advance(options) options = options.dup d = self d = d >> options.delete(:years) * 12 if options[:years] d = d >> options.delete(:months) if options[:months] d = d + options.delete(:weeks) * 7 if options[:weeks] d = d + options.delete(:days) if options[:days] d end end \XFFLT^

Slide 50

Slide 50 text

class Date def advance(options) options = options.dup d = self d = d >> options.delete(:years) * 12 if options[:years] d = d >> options.delete(:months) if options[:months] d = d + options.delete(:weeks) * 7 if options[:weeks] d = d + options.delete(:days) if options[:days] d end end \XFFLT^

Slide 51

Slide 51 text

class Date def advance(options) options = options.dup d = self d = d >> options.delete(:years) * 12 if options[:years] d = d >> options.delete(:months) if options[:months] d = d + options.delete(:weeks) * 7 if options[:weeks] d = d + options.delete(:days) if options[:days] d end end \XFFLT^ ೔લͷ೔෇

Slide 52

Slide 52 text

ͪͳΈʹɺ
 ඪ४ͷ%BUFͷ࿩Ͱ͕͢

Slide 53

Slide 53 text

class Date def advance(options) options = options.dup d = self d = d >> options.delete(:years) * 12 if options[:years] d = d >> options.delete(:months) if options[:months] d = d + options.delete(:weeks) * 7 if options[:weeks] d = d + options.delete(:days) if options[:days] d end end ݄ͷԋࢉ%BUF

Slide 54

Slide 54 text

# nϲ݄ޙΛฦ͢ # ରԠ͢Δ݄ͷಉ͡೔͕ฦΔ Date.new(2001,1,28) >> 1 #=> # # ରԠ͢Δ݄ʹಉ͡೔͕ͳ͍৔߹͸ɺ຤೔͕ฦΔ Date.new(2001,1,31) >> 1 #=> # # ͦͷͨΊɺૢ࡞ͷ࢓ํʹΑͬͯ͸༧ظ͠ͳ͍ৼΔ෣͍Λ͢ΔՄೳੑ͕͋Δ Date.new(2001,1,31) >> 2 #=> # Date.new(2001,1,31) >> 1 >> 1 #=> # Date.new(2001,1,31) >> 1 >> -1 #=> #

Slide 55

Slide 55 text

class DateTime def advance(options) unless options[:weeks].nil? options[:weeks], partial_weeks = options[:weeks].divmod(1) options[:days] = options.fetch(:days, 0) + 7 * partial_weeks end unless options[:days].nil? options[:days], partial_days = options[:days].divmod(1) options[:hours] = options.fetch(:hours, 0) + 24 * partial_days end d = to_date.advance(options) datetime_advanced_by_date = change(year: d.year, month: d.month, day: d.day) seconds_to_advance = \ options.fetch(:seconds, 0) + options.fetch(:minutes, 0) * 60 + options.fetch(:hours, 0) * 3600 if seconds_to_advance.zero? datetime_advanced_by_date else datetime_advanced_by_date.since(seconds_to_advance) end end end \XFFLT^ िؒલͷ೔෇

Slide 56

Slide 56 text

class DateTime def advance(options) unless options[:weeks].nil? options[:weeks], partial_weeks = options[:weeks].divmod(1) options[:days] = options.fetch(:days, 0) + 7 * partial_weeks end unless options[:days].nil? options[:days], partial_days = options[:days].divmod(1) options[:hours] = options.fetch(:hours, 0) + 24 * partial_days end d = to_date.advance(options) datetime_advanced_by_date = change(year: d.year, month: d.month, day: d.day) seconds_to_advance = \ options.fetch(:seconds, 0) + options.fetch(:minutes, 0) * 60 + options.fetch(:hours, 0) * 3600 if seconds_to_advance.zero? datetime_advanced_by_date else datetime_advanced_by_date.since(seconds_to_advance) end end end \XFFLT^ ೥݄೔͚ͩΛมߋ

Slide 57

Slide 57 text

class DateTime def advance(options) unless options[:weeks].nil? options[:weeks], partial_weeks = options[:weeks].divmod(1) options[:days] = options.fetch(:days, 0) + 7 * partial_weeks end unless options[:days].nil? options[:days], partial_days = options[:days].divmod(1) options[:hours] = options.fetch(:hours, 0) + 24 * partial_days end d = to_date.advance(options) datetime_advanced_by_date = change(year: d.year, month: d.month, day: d.day) seconds_to_advance = \ options.fetch(:seconds, 0) + options.fetch(:minutes, 0) * 60 + options.fetch(:hours, 0) * 3600 if seconds_to_advance.zero? datetime_advanced_by_date else datetime_advanced_by_date.since(seconds_to_advance) end end end \XFFLT^ ೥݄೔͚ͩΛมߋͨ͠%BUFUJNF

Slide 58

Slide 58 text

class DateTime def advance(options) unless options[:weeks].nil? options[:weeks], partial_weeks = options[:weeks].divmod(1) options[:days] = options.fetch(:days, 0) + 7 * partial_weeks end unless options[:days].nil? options[:days], partial_days = options[:days].divmod(1) options[:hours] = options.fetch(:hours, 0) + 24 * partial_days end d = to_date.advance(options) datetime_advanced_by_date = change(year: d.year, month: d.month, day: d.day) seconds_to_advance = \ options.fetch(:seconds, 0) + options.fetch(:minutes, 0) * 60 + options.fetch(:hours, 0) * 3600 if seconds_to_advance.zero? datetime_advanced_by_date else datetime_advanced_by_date.since(seconds_to_advance) end end end \XFFLT^

Slide 59

Slide 59 text

class DateTime def advance(options) unless options[:weeks].nil? options[:weeks], partial_weeks = options[:weeks].divmod(1) options[:days] = options.fetch(:days, 0) + 7 * partial_weeks end unless options[:days].nil? options[:days], partial_days = options[:days].divmod(1) options[:hours] = options.fetch(:hours, 0) + 24 * partial_days end d = to_date.advance(options) datetime_advanced_by_date = change(year: d.year, month: d.month, day: d.day) seconds_to_advance = \ options.fetch(:seconds, 0) + options.fetch(:minutes, 0) * 60 + options.fetch(:hours, 0) * 3600 if seconds_to_advance.zero? datetime_advanced_by_date else datetime_advanced_by_date.since(seconds_to_advance) end end end \XFFLT^ िؒલͷ%BUFUJNF

Slide 60

Slide 60 text

module ActiveSupport class Duration private def sum(sign, time = ::Time.current) parts.inject(time) do |t, (type, number)| if t.acts_like?(:time) || t.acts_like?(:date) if type == :seconds t.since(sign * number) elsif type == :minutes t.since(sign * number * 60) elsif type == :hours t.since(sign * number * 3600) else t.advance(type => sign * number) end else raise ::ArgumentError, "expected a time or date, got #{time.inspect}" end end end end end

Slide 61

Slide 61 text

module ActiveSupport class Duration def ago(time = ::Time.current) sum(-1, time) end alias :until :ago alias :before :ago end end

Slide 62

Slide 62 text

XFFLTBHP %BUFUJNF

Slide 63

Slide 63 text

·ͱΊ

Slide 64

Slide 64 text

w /VNFSJD΍*OUFHFSʹNJOVUFTͳͲͷϝιουΛ௥Ճͯ͠%VSBUJPO ΦϒδΣΫτΛฦ͍ͯ͠Δ w %VSBUJPO͸ඵ਺Λද͢WBMVFͱ֤୯Ґͱͦͷ஋ͷ૊Έ߹ΘͤͷQBSUT Λ͍࣋ͬͯΔ w ೔࣌Λܭࢉ͢Δͱ͖͸QBSUTΛ࢖ͬͯܭࢉ͍ͯ͠Δ

Slide 65

Slide 65 text

͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ