sts10 / radiation

A simple blog CMS for totallynuclear.club pages.
MIT License
16 stars 3 forks source link

Timezone support #3

Open erikcore opened 9 years ago

erikcore commented 9 years ago

This seems like it would be really easy to build into the installation flow (but what the hell do I know).

Once I had Radiation installed, I hardcoded timezone support by hardcoding in lib/post at line 21:

current_time = Time.new.in_timezone('America/New_York’)

and making my config/environment look like this:

require 'erb'
require 'date'
require 'tzinfo'
require 'active_support'

require_relative '../lib/post'

require_relative '../lib/blog'

class Time

   require 'tzinfo'

   # tzstring e.g. 'America/Los_Angeles'

   def in_timezone tzstring

   tz = TZInfo::Timezone.get tzstring

   p = tz.period_for_utc self

   e = self.localtime(p.utc_offset)

   if !e.isdst

      e = e + 60*60

   end

   e

   end

end

If I had time I'd do this myself but I'm busy blah blah blah.

sts10 commented 9 years ago

Oh super cool. Yeah this was on my list of things to figure out.

Two questions: In my test my post is gets a time stamp of one hour ahead. I think it's because it should be if e.isdst add an hour, rather than if !e.isdst right?

Second question: Are you thinking that I just put system "gem install tzinfo" and system "gem install active_support" in the runner.rb setup code? I'm assuming they aren't installed by default on tilde club boxes.

erikcore commented 9 years ago

I had to install those gems for sure. Also, you're probably right about the subtracting an hour thing. I was really just winging it and it was producing the results I needed at the time (before the time change).

sts10 commented 9 years ago

Alright so I just pushed v 0.2.0 which has some level of time-zone support. I made a larger change in that I extracted 4 "user settings" to a user_settings.rb file and then created a new main menu option to edit that file.

By default it's:

$my_timezone = 'America/New_York'
$my_text_editor_command = 'vim'
$my_blog_location = '../public_html/blog.html'

# Only change this one if you know what you're doing!
$my_template_location = '../radiation_templates/blog.html.erb'

Also, turns out you don't need active_support, so I only added gem install tzinfo to the setup script.

Erik, Do you know what other options there are for tzstring besides "America/New_York" and "America/Los_Angeles"? Is there a list of options somewhere online that I can provide a URL to in a comment? This silly form thing (http://www.timezoneconverter.com/cgi-bin/zoneinfo) is the closest I could find, but I haven't tested any other options other than 'America/New_York'

bobbyllama commented 9 years ago

Hi. I just started using Radiation to manage my tildepage and love it. Thanks for the hard work!

However, I'm curious if this new update will conflict with my current setup. In order to get Screen and Radiation to use the correct time, I updated my .bash_profile to automatically adjust to my actual timezone. Will this interfere with Radiation's new setup?

sts10 commented 9 years ago

I would guess that it would not interfere, but if you have any trouble just go into lib/post and change line 21 to read

current_time = Time.new

Update: I just pushed version 0.2.1 which allows users to set the timezone to '' if they just want to use the default.

bobbyllama commented 9 years ago

Great, thanks for the response. I will attempt to update a little later.

Is there a smooth way to update the package? If I attempt to re-git, it errors out saying that the directory already exists. Should I remove the radiation directory and install as new?

sts10 commented 9 years ago

So there's at least 2 way to update.

The best way is to do a real re-install. Remove the radiation folder by running rm -rf ~/radiation and re- clone it down as per installation instructions. Your posts and templates should live safety outside that folder.

The second way, which may not update it correctly, is to cd into the radiation directory and run git pull origin master. I think that will work for non-contributors. But again, especially with these recent updates, you're better off removing and re-installing.

I wish there was a smoother way to update it. Honestly I thought there would only be a handful of users. One idea I've been thinking about is making it a Ruby gem, which has a nice update functionality built in. But for now I like that users can and should frequently do a clean re-install.

bobbyllama commented 9 years ago

Newest release is installed and running perfectly.

Here's some additional info on the TZ variables if you still need it.

sts10 commented 9 years ago

Thanks man. Apologies but I just pushed a new version with Markdown support. You'll need to do a full re-install again if you want it-- sorry!