Skip to content

Commit

Permalink
Cache @rweek and @rday, not @ref
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Mar 23, 2024
1 parent 1104802 commit 78896d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## et-orbi 1.2.11 not yet released

- Cache @rweek and @rday, not @ref, gh-38


## et-orbi 1.2.10 released 2024-03-22

Expand Down
23 changes: 14 additions & 9 deletions lib/et-orbi/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def initialize(s, zone)
def touch

@time = nil
@ref = nil
@rday = nil
@rweek = nil
end

def seconds=(f)
Expand Down Expand Up @@ -353,20 +354,24 @@ def wday_in_month
#
def rweek

@ref ||= EtOrbi.make_time('2019-01-01 12:00:00', @zone)
noon = EtOrbi.make_time(strftime('%F 12:00:00'), @zone)

((noon - @ref) / WEEK_S).floor + 1
@rweek ||=
begin
ref = EtOrbi.make_time('2019-01-01 12:00:00', @zone)
noon = EtOrbi.make_time(strftime('%F 12:00:00'), @zone)
((noon - ref) / WEEK_S).floor + 1
end
end

# "reference week", used in fugit for cron modulo notation
#
def rday

@ref ||= EtOrbi.make_time('2019-01-01 12:00:00', @zone)
noon = EtOrbi.make_time(strftime('%F 12:00:00'), @zone)

((noon - @ref) / DAY_S).floor + 1
@rday ||=
begin
ref = EtOrbi.make_time('2019-01-01 12:00:00', @zone)
noon = EtOrbi.make_time(strftime('%F 12:00:00'), @zone)
((noon - ref) / DAY_S).floor + 1
end
end

def reach(points)
Expand Down

0 comments on commit 78896d7

Please sign in to comment.