timecop
Version, currently master branch1 version
- master branchlatestJun 18, 2018
github.com/tobyapi/timecop.cr
A timecop inspire library allowing "time travel", "freezing time" and "time acceleration".
17 stars
0 dependents
License: MIT
Installation
# Add this to your shard.yml
dependencies:
timecop:
github: tobyapi/timecop.cr
branch: mastermaster is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
0.25.0- License
- MIT
- Author
- TobiasGSmollett <landofscala@gmail.com>
Dependencies
This version declares no dependencies.
README
# timecop.cr
[](https://travis-ci.org/TobiasGSmollett/timecop.cr)
A [timecop](https://github.com/travisjeffery/timecop) inspire library allow "time travel", "freezing time" and "time acceleration" capabilities, making it simple to test time-dependent code.
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
timecop:
github: TobiasGSmollett/timecop.cr
```
## Usage
```crystal
require "timecop"
```
### Timecop.freeze
```crystal
date = Time.new(2008, 10, 10, 10, 10, 10)
Timecop.freeze(date) do |frozen_time|
puts "#{frozen_time == Time.now}" # => true
end
```
### Timecop.travel
```crystal
Timecop.travel(Time.new(2014, 1, 1, 0, 0, 0)) do
puts Time.now # => 2014-01-01 00:00:00 +0900
sleep(5)
puts Time.now # => 2014-01-01 00:00:05 +0900
end
```
### Timecop.scale
```crystal
# seconds will now seem like hours
Timecop.scale(Time.now, 3600)
puts Time.now # => 2017-08-28 23:50:06 +0900
sleep(2.0)
# seconds later, hours have passed and it's gone from 23pm at night to 1am in the morning
puts Time.now # => 2017-08-29 01:50:21 +0900
```
### Timecop.safe_mode
```crystal
# turn on safe mode
Timecop.safe_mode = true
Timecop.safe_mode? # => true
# using method without block
Timecop.freeze Time.new(2008, 10, 10, 10, 10, 10)
# => Timecop::SafeModeException: Safe mode is enabled, only calls passing a block are allowed.
```
## Development
Pull Request 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
- [TobiasGSmollett](https://github.com/TobiasGSmollett) TobiasGSmollett - creator, maintainer
## Thanks
Thanks to Travis Jeffery for his awesome work on [timecop](https://github.com/travisjeffery/timecop).
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
master- Seen
- Jun 18, 2018
- Crystal
0.25.0- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/tobyapi/timecop.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 12, 2026
- Synced
- Aug 12, 2026
- Versions
- 1