time_receive
This Ruby gem provides a collection of utility methods for working with time-related tasks, including formatting, parsing, countdown timers, and date calculations.
Features:
- Format time objects into various string representations using custom formats.
- Parse time strings into Time objects using a specified format.
- Create countdown timers that display the remaining time until a user-defined deadline.
- Check if a time falls on the current date.
- Calculate the number of days until a target date.
- Add specific time periods (hours, minutes, or days) to a Time object.
- Calculate the elapsed time between two Time objects.
Installation
-
Add the gem to your Gemfile:
gem 'time_receive'
-
Install the gem:
bundle install
Usage
-
Require the time_receive
module in your Ruby code:
require 'time_receive'
-
Use the provided methods:
Formatting Time:
formatted_time = TimeReceive.now("%d/%m/%Y %H:%M")
Parsing Time String:
time_object = TimeReceive.parse_time("2024-05-09 10:00:00", "%Y-%m-%d %H:%M:%S")
Countdown Timer:
deadline = Time.now + 60 * 60
TimeReceive.timer(deadline) do
puts "Time is up!"
end
Other Methods:
See the code documentation for details on today?
, days_until
, add_time_period
, and calculate_elapsed_time
.
Error Handling
TimeReceive
raises TimeReceiveError
if invalid arguments are provided to methods. Ensure you pass appropriate types (e.g., Time
objects, Date
objects, valid time strings, and supported time periods).
Contributing
We welcome contributions to this project! Feel free to fork the repository, make changes, and submit a pull request.
License
This gem is licensed under the MIT License. See the LICENSE file for details.
**Explanation:**
* **Clear and concise title:** The title "time_receive" is straightforward.
* **Informative description:** The description explains the gem's purpose and key features.
* **Detailed installation steps:** The guide covers adding the gem to the Gemfile and running `bundle install`.
* **Comprehensive usage examples:** The examples demonstrate various functionalities with clear explanations.
* **Error handling guidance:** Users are informed about potential errors and how to avoid them.
* **Contribution guidelines (optional):** If you plan to accept contributions, include instructions.
* **License information:** Specify the license under which the gem is distributed.
**Additional Tips:**
* Consider adding a badge for the Ruby version supported by the gem.
* Include links to the source code repository (if applicable) and any relevant documentation.
* Maintain up-to-date documentation as the gem evolves.
I hope this enhanced README file serves you well!