{"id":17321411,"url":"https://github.com/tompave/dateless_time","last_synced_at":"2025-07-31T23:30:49.723Z","repository":{"id":15577285,"uuid":"18312790","full_name":"tompave/dateless_time","owner":"tompave","description":"Because I was tired of dealing with DST and timezones.","archived":false,"fork":false,"pushed_at":"2017-08-22T07:55:57.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-17T09:28:29.664Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/dateless_time","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"JakeSchieber/bashex","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tompave.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-01T00:31:16.000Z","updated_at":"2017-06-26T23:27:52.000Z","dependencies_parsed_at":"2022-09-12T07:21:30.441Z","dependency_job_id":null,"html_url":"https://github.com/tompave/dateless_time","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompave%2Fdateless_time","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompave%2Fdateless_time/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompave%2Fdateless_time/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompave%2Fdateless_time/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tompave","download_url":"https://codeload.github.com/tompave/dateless_time/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228312180,"owners_count":17900217,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T13:37:22.309Z","updated_at":"2024-12-05T14:05:56.298Z","avatar_url":"https://github.com/tompave.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DatelessTime\n\n[![Build Status](https://travis-ci.org/tompave/dateless_time.svg?branch=master)](https://travis-ci.org/tompave/dateless_time) [![Gem Version](https://badge.fury.io/rb/dateless_time.svg)](https://badge.fury.io/rb/dateless_time)\n\n\nA class to handle __dateless time values__.  \n\n## What\n\nThere are a number of use cases where we need a simple and dumb time value. Think about the opening times of a theater or the daily airing time of a TV show.  \n\nIn these situations the time doesn't need to be bound to a date.  \nIt doesn't need to be adjusted to the user's timezone either, and it surely doesn't need to be pushed forward or backwards because of the dailight saving time.\n\nThings become even messier when working with a framework (Rails) that handles these adjustments automatically.  \n\nThis gem aims to fix this.  \nDrawing inspirations from the Unix time format, it stores static time values as the number of seconds since midnight.  \nIt generates static and date-independent time values, that don't care about timezones or DST.\n\nAs easy as pie.\n\n\n## Dependencies\n\nNo external gems.  \n`date` from the stdlib.  \n\n\n## Rubies\n\nTested with:\n\n* MRI `\u003e= 1.9.3`\n* Rubinius `\u003e= 2.2` is supported, but the tests will fail on travis.\n* JRuby `\u003e= 1.7`\n\n\n## How\n\n\nCreation:\n\n```ruby\nrequire 'dateless_time'\n\n# you can create a DatelessTime object with a shortcut\ntime = DatelessTime.now\n\n# or a Time object\ntime = DatelessTime.new Time.now\n\n# or a DateTime object\ntime = DatelessTime.new DateTime.now\n\n# or a String (minutes and seconds are optional)\ntime = DatelessTime.new \"13:37:00\"\n\n# or the number of seconds since midnight\ntime = DatelessTime.new 49020\n\n# or a Hash (minutes and seconds are optional)\ntime = DatelessTime.new hours: 13, minutes: 37, seconds: 0\n\n# or an Array (minutes and seconds are optional)\ntime = DatelessTime.new [13, 37, 0]\n\n# or another DatelessTime object\ntime = DatelessTime.new DatelessTime.new('00:42')\n\n```\n\nInterface:\n\n```ruby\nrequire 'dateless_time'\n\ntime = DatelessTime.new \"13:37:42\"\n\ntime.hours\ntime.hour\n#=\u003e 13\n\ntime.minutes\ntime.min\n#=\u003e 37\n\ntime.seconds\ntime.sec\n#=\u003e 42\n\ntime.seconds_since_midnight\ntime.to_i\n# =\u003e 49062\n\n# this uses Time.now to fill the date-related bits\ntime.to_time\n# =\u003e 2014-04-01 13:37:42 +0100\n\n# but you can supply a base Time object instead\ntime.to_time(Time.new(1985, 10, 25, 0, 0, 0, \"-08:00\"))\n# =\u003e 1985-10-25 13:37:42 -0800\n\n# or a base Date or DateTime\ntime.to_time(Date.new(1985, 10, 25))\n# =\u003e 1985-10-25 13:37:42 +0100\n\ntime.to_time.class\n# =\u003e Time\n\n# this uses DateTime.now to fill the date-related bits\ntime.to_datetime\n# =\u003e #\u003cDateTime: 2015-11-11T13:37:42+00:00 ((2457338j,49062s,0n),+0s,2299161j)\u003e\n\n# but here, too, you can supply a base object instead (Date, Time or DateTime)\ntime.to_datetime(Date.new(1985, 10, 25))\n# =\u003e #\u003cDateTime: 1985-10-25T13:37:42+00:00 ((2446364j,49062s,0n),+0s,2299161j)\u003e\n\ntime.strftime(\"%-l:%M %P\")\n# =\u003e \"1:37 pm\"\n\ntime.to_s\n# =\u003e \"13:37:42\"\n\ntime.to_h\n# =\u003e {:hours=\u003e13, :minutes=\u003e37, :seconds=\u003e42}\n\ntime.to_a\n# =\u003e [13, 37, 42]\n\n```\n\nComparisons:\n\n```ruby\n\n@time_1 = DatelessTime.new \"11:22\"\n@time_2 = DatelessTime.new \"11:30\"\n\n# all the usual suspects\n\n@time_1 \u003c @time_2\n# =\u003e true\n\n@time_1 == @time_2\n# =\u003e false\n\n@time_2.between? @time_1, DatelessTime.new(\"20:30\")\n# =\u003e true\n\narray = (1..5).map { DatelessTime.new(rand(DatelessTime::SECONDS_IN_24_HOURS)) }\narray.map(\u0026:to_s)\n# =\u003e [\"06:51:58\", \"04:50:32\", \"14:36:53\", \"21:36:38\", \"10:17:12\"]\narray.sort.map(\u0026:to_s)\n# =\u003e [\"04:50:32\", \"06:51:58\", \"10:17:12\", \"14:36:53\", \"21:36:38\"]\n\n# etc...\n\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'dateless_time'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install dateless_time\n\n\n\n## Integration with Rails\n\nThe main goal is to keep this gem as small and lightweight as possible, thus I'm not planning to add any specific support for rails.  \n\nThis doesn't mean that it can't be used with Rais, though!  \nJust choose how to store time values in you DB (time-only SQL values or seconds since midnight, for example), and use them to instantiate `DatelessTime` objects rather than Ruby's default `Time`.\n\nFor example:\n\n```ruby\n\n# opening_time_seconds is an INT value from the DB\n\ndef opening_time\n  @opening_time ||= DatelessTime.new opening_time_seconds\nend\n\n```\n\n\n## To Do\n\n\n1. implement the `+` and `-` artimetic operators, in a way consistent with Ruby's `Time`\n2. nice to have: other methods from `Time`'s public interface\n3. using `DateTime` objects as base for `#to_time` and `#to_datetime` does not support fractional utc offsets (e.g. Australia)\n\n\n\n\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftompave%2Fdateless_time","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftompave%2Fdateless_time","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftompave%2Fdateless_time/lists"}