forked from publify/publify
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
255 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
config/database.yml | ||
config/mail.yml | ||
config/timezone.yml | ||
config/secret.token | ||
*.log | ||
*~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
'Tokyo' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
class PublifyTime | ||
def self.delta(year = nil, month = nil, day = nil) | ||
return nil if year.nil? && month.nil? && day.nil? | ||
from = Time.utc(year, month || 1, day || 1) | ||
to = from.next_year | ||
to = from.next_month unless month.blank? | ||
to = from + 1.day unless day.blank? | ||
to = to - 1 # pull off 1 second so we don't overlap onto the next day | ||
year = year.to_i unless year.nil? | ||
month = month.to_i unless month.nil? | ||
day = day.to_i unless day.nil? | ||
from = Time.zone.local(year, month, day) | ||
to = from.end_of_year | ||
to = from.end_of_month unless month.blank? | ||
to = from.end_of_day unless day.blank? | ||
from..to | ||
end | ||
|
||
def self.delta_like(str) | ||
case str | ||
when /(\d{4})-(\d{2})-(\d{2})/ | ||
delta(Regexp.last_match(1),Regexp.last_match(2),Regexp.last_match(3)) | ||
|
||
when /(\d{4})-(\d{2})/ | ||
delta(Regexp.last_match(1),Regexp.last_match(2)) | ||
|
||
when /(\d{4})/ | ||
delta(Regexp.last_match(1)) | ||
|
||
else | ||
str | ||
end | ||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters