Code Monkey home page Code Monkey logo

timecop.cr's Introduction

timecop.cr

CI Releases License

A timecop inspired library to allow easy manipulation of time in tests. Originally authored by TobiasGSmollett.

Installation

Add this to your application's shard.yml:

dependencies:
+  timecop:
+    github: crystal-community/timecop.cr

Usage

require "timecop"

Timecop.freeze

time = Time.local(2008, 10, 10, 10, 10, 10)
Timecop.freeze(time) do |frozen_time|
  frozen_time == Time.local # => true
end

Timecop.travel

Timecop.travel(Time.local(2014, 1, 1, 0, 0, 0)) do
  Time.local # => "2014-01-01 00:00:00 +0900"
  sleep(5.seconds)
  Time.local # => "2014-01-01 00:00:05 +0900"
end

Timecop.scale

# seconds will now seem like hours
Timecop.scale(3600)

Time.local # => "2017-08-28 23:50:06 +0900"

sleep(2.seconds)
# 2 seconds later, hours have passed and it's gone from
# 23pm at night to 1am in the morning

Time.local # => "2017-08-29 01:50:21 +0900"

Timecop.safe_mode

Timecop.safe_mode? # => false
Timecop.safe_mode = true

# using method without block
Timecop.freeze Time.local(2008, 10, 10, 10, 10, 10)
# => raises Timecop::SafeModeException

Development

Pull Requests Welcome!

Contributing

  1. Fork it (https://github.com/TobiasGSmollett/timecop.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Thanks

Thanks to Travis Jeffery for his awesome work on timecop.

timecop.cr's People

Contributors

fsdevblog avatar icy-arctic-fox avatar robacarp avatar sija avatar tobyapi avatar veelenga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

timecop.cr's Issues

Time.measure isn't affected by Timecop.scale in 0.4.1

In the sample below I expected duration to be roughly 100:

require "timecop"

n = Time::Span.new

Timecop.scale 100 do
  # 1 wallclock second should measure as 100 seconds
  duration = Time.measure do
    sleep 1
  end

  pp duration
  # => 00:00:01.001259792
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.