Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed rule_for_reference to use timestamps where possible #11

Merged
merged 4 commits into from
May 16, 2012
Merged

Changed rule_for_reference to use timestamps where possible #11

merged 4 commits into from
May 16, 2012

Conversation

nessche
Copy link
Contributor

@nessche nessche commented May 14, 2012

Hi,
while hunting for the DST bug, I noticed that the code was parsing strings also when timestamps were present, so I slightly changed the rule_for_reference code to use timestamps, if present. I tried executing rule_for_reference 10000 times in a row, and it shows that using timestamps is roughly 9 times faster than parsing a string with strptime.

The existing tests are now using the new functionality, and I added a new test (and a data without timestamps) to test the case where no timestamps are available.

If during the existence of this library you have already found a reason why timestamps should not be used, just discard this pull request.

@rules.detect{ |rule| _parsetime(rule['_from']) <= reference && _parsetime(rule['_to']) > reference }
@rules.detect do |rule|
if rule['from'] and rule['to']
from = Time.at(rule['from'].to_i / 1000.0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you refactor this logic into a private parsetime function? (similar to _parsetime)

end
end

def _read_timestamp timestamp #:nodoc:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I called the function _read_timestamp, I also added a begin/rescue/end block, in case the timestamp is malformed. Feel free to pull in the changes and then rename/refactor as you see fit,

@panthomakos
Copy link
Owner

Awesome!

panthomakos added a commit that referenced this pull request May 16, 2012
Changed rule_for_reference to use timestamps where possible
@panthomakos panthomakos merged commit 488513a into panthomakos:master May 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants