This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
commit 598bdbecabb0b78736bfa6fce47b87c45b09e2fd
tree 4d45ee6fcfa6c6b00538d1aa221f761f57e72371
parent 3d8cd7899f67ca0c1c03695103713be8464d0afc
tree 4d45ee6fcfa6c6b00538d1aa221f761f57e72371
parent 3d8cd7899f67ca0c1c03695103713be8464d0afc
tz_time /
README
TzTime
======
[Boring Introduction]
TzTime is a wrapper for the Time class. It associates a time instance with a time zone, and keeps the two together. It
quacks very much like a Time instance, and even provides the same extension methods that Rails adds to time objects.
By combining the time and the time zone in a single time-like class, you can simplify much of the time-zone gymnastics
that you were previously forced to do.
[Exciting Introduction]
TzTime is subversive. It even _sounds_ subversive, like sharp incisors snicking together in the dark. It sneaks into
your app from the inside and stuffs time zone support into the cracks. It's like a little ruby-colored rat, poking
around in the under-basement of your code, but instead of chewing away at the infrastructure with its sharp little teeth
(and believe me, they _are_ sharp), it builds fluffy (and oh, so comfortable!) little time-zone flavored nests wherever
it can.
This look familiar?
class TasksController < ApplicationController
def create
task = account.tasks.build(params[:task])
task.alert_at = current_user.time_zone.local_to_utc(task.alert_at)
task.save!
end
end
Oh, that awful bloating sensation! Because the time zone is not globally accessible, you have to jump through hoop and
ungainly hoop in your controllers...or pass the unfortunate time zone to method after method.
No more! Let the Rodent of Unusually Fine TZ Acumen aid you:
class ApplicationController < ActionController:Base
around_filter :set_timezone
private
def set_timezone
TzTime.zone = current_user.time_zone
yield
TzTime.reset!
end
end
class Task < ActiveRecord::Base
tz_time_attributes :alert_at
end
class TasksController < ApplicationController
def create
task = account.tasks.create(params[:task])
end
end
Let the rat cart the time-zone around for you! Refactor those nasty time zone conversions into your model, where they
belong. Soar through the heady winds of your application's stratosphere, comfortable in the knowledge that you have
helpful little rats scurrying about in the dark.
Or maybe they're gnomes.








