jeremyw / stamp Goto Github PK
View Code? Open in Web Editor NEWDate and time formatting for humans.
License: MIT License
Date and time formatting for humans.
License: MIT License
Seems like a simple oversight, and can be easily fixed.
Hi. I'm calling #stamp with today's date as the parameter, and getting some weird output. It seems to work correctly when 31/12
is used as the stamp parameter, as suggested in the readme. That said, I thought I'd report it because the output - "28/13/2013"
- doesn't contain any valid months, so I'm not sure how it came about.
1.9.3p286 :015 > d = Date.new(2013, 01, 28)
=> Mon, 28 Jan 2013
1.9.3p286 :017 > d.stamp "29/01/2013"
=> "28/13/2013"
1.9.3p286 :016 > d.stamp "31/12/2013"
=> "28/01/2013"
I'm using stamp 0.5.0, rails 3.2.11, and ruby 1.9.3.
I wonder if the leading space in the output could be suppressed for a format such as "3:00pm"?
ruby-1.9.2-p180 :003 > Time.now.stamp("3:00pm")
=> " 9:55am"
ruby-1.9.2-p180 :004 >
Time.now.strftime("%P") isn't implemented in Ruby 1.8.7, so stamp("5 am") outputs "5 P".
t = Time.current.stamp('14:00 UTC')
and t = Time.current.in_time_zone('any time zone').stamp('14:00 UTC')
both return just the time with the string UTC. For some reason UTC is not being parsed correctly and replaced with the actual timezone.
Add support for stamp examples in i18n formats:
en:
date:
formats:
default: "1999-01-31"
short: "Jan 1"
long: "January 1, 1999"
Some people have expressed concern that the method name "stamp" isn't descriptive enough to people unfamiliar with the gem. Consider adding #stamp_like and #format_like as aliases.
See http://search.cpan.org/~roode/Time-Format-1.02/Format.pm
Support formatting directives like "Month d, yyyy", "mm/dd/yy", etc.
You dolt.
ruby-1.9.2-p180 :001 > require 'stamp'
=> true
ruby-1.9.2-p180 :002 > date = Date.new(2011, 11, 12)
=> #<Date: 2011-11-12 (4911755/2,0,2299161)>
ruby-1.9.2-p180 :003 > date.stamp("21 Aug 2011, 11:15pm")
=> "11 Nov 2011, 12:00am"
Should be "12 Nov 2011"
Why use included callback?
def self.included(klass)
klass.class_eval do
include InstanceMethods
end
end
module InstanceMethods
I don't see any need for it. Just put everything in Stamp.
I know this gem isn't specifically written for Rails, but I'm having a small problem and I was hoping you might be able to point me in the right direction. I'm using Rails 3.2.6 and I'm running the following code in the Rails console:
Time.zone.now.format_like('January 1, 2000 at 1:59 PM %Z')
=> "June 21, 2012 at 10:16 PM UTC"
Time.zone.now.strftime('%B %e, %Y at %l:%M %p %Z')
=> "June 21, 2012 at 10:17 PM EDT"
My app is set up to use Eastern Time and the date and time seem correct. However, the timezone name should be 'EDT'. Just using strftime the timezone name works just fine.
Any ideas why this is happening?
Temple seems to provide the compilation and transformations that are needed.
It is also quite quick. Many of the fast erb replacements are using it like slim and hamlit
but it adds a dependency.
if it sounds good, I'll look into this in my copious free time. (wanted to swing back in 2015... darn)
I'm considering dropping support for 1.8.7. There are a couple hacks in the code to deal with it:
https://github.com/jeremyw/stamp/blob/master/lib/stamp/translator.rb#L116-L121
d3330fd
Are there any stamp users on 1.8.7 who really really care about continued support?
I wanted to get your thoughts and maybe some ideas on how to implement this. I tried implementing it in my fork on Friday for a few hours but I just couldn't get it to work. (although regex isn't my forte)
Ideally, I would like to be able to do something like:
Time.now.stamp("31st Oct 2012")
# => "5th Nov 2012"
or even
Time.now.stamp("Oct 2nd 2012")
# => "Nov 5th 2012"
Stamp is built as a parser for strftime formats and currently Ruby's strftime doesn't support ordinals in the date. That's what it's so difficult to write it. =/
Let me know what you think.
1.9.2p320 :015 > Date.new(2012, 10, 1).format_like 'Thu, Oct 11, 1988'
=> "Mon, Oct 01, 2012"
1.9.2p320 :016 > Date.new(2012, 10, 1).format_like 'Thu, Oct 12, 1988'
=> "Mon, Oct 10, 2012"
1.9.2p320 :017 > Date.new(2012, 10, 1).format_like 'Thu, Oct 13, 1988'
=> "Mon, Oct 01, 2012"
Error is in the middle call.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.