Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > regualr expression (need help)

Reply
Thread Tools

regualr expression (need help)

 
 
Heinrich Piard
Guest
Posts: n/a
 
      01-13-2008
Hi all,

anybody an idea how to transform the date out of this string
Not After : Apr 3 11:13:11 2008 GMT

to

2008-4-3


Help is very apreciated!!

Thx.

Henry
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Sebastian Hungerecker
Guest
Posts: n/a
 
      01-13-2008
Heinrich Piard wrote:
> anybody an idea how to transform the date out of this string
> Not After : Apr 3 11:13:11 2008 GMT
>
> to
>
> 2008-4-3


Time.parse("Not After : Apr 3 11:13:11 2008 GMT") will give you a Time
object. You can get the desired string from that quite easily (using strftime
for example, or just using Time#day, Time#month and Time#year directly).

HTH,
Sebastian
--
Jabber: http://www.velocityreviews.com/forums/(E-Mail Removed)
ICQ: 205544826

 
Reply With Quote
 
 
 
 
Daniel Finnie
Guest
Posts: n/a
 
      01-13-2008
[Note: parts of this message were removed to make it a legal post.]

I would create a time object and then format it how you like.

Time.parse(string).strftime(format_string)

Look up the docs for Time#strftime to determine the format string.

On Jan 13, 2008 12:04 PM, Heinrich Piard <(E-Mail Removed)> wrote:

> Hi all,
>
> anybody an idea how to transform the date out of this string
> Not After : Apr 3 11:13:11 2008 GMT
>
> to
>
> 2008-4-3
>
>
> Help is very apreciated!!
>
> Thx.
>
> Henry
> --
> Posted via http://www.ruby-forum.com/.
>
>


 
Reply With Quote
 
Heinrich Piard
Guest
Posts: n/a
 
      01-13-2008
Daniel Finnie wrote:
> I would create a time object and then format it how you like.
>
> Time.parse(string).strftime(format_string)
>
> Look up the docs for Time#strftime to determine the format string.



Guys - thanks a lot.
It works just great!!

Here the snipped:
ValidDate = File.open("someFile.txt").readlines.to_s.grep(/Not After/)
#puts 'Certificate is valid ' + ValidDate.to_s
CertValidDate = Time.parse(ValidDate.to_s).strftime("%Y-%d-%m")
#puts CertValidDate

Now I can do my comparison with actualDate and CertValidDAte and I am
able to create an alarm.

Thanks!!!

bye
Henry
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
louis
Guest
Posts: n/a
 
      01-13-2008
sorry to post what might be a moronic question, but i although
Time.parse shows up in the online core docs, Time.parse isn't a method
on any machine of mine.

e.g.

irb(main):001:0> Time.methods.sort
=> [:"!", :"!=", :"!~", :<, :<=, :<=>, :==, :===, :=~, :>, :>=,
:__id__, :__send__, :_load, :allocate, :ancestors, :at, :autoload,
:autoload?, :class, :class_eval, :class_exec,
:class_variable_defined?, :class_variable_get, :class_variable_set,
:class_variables, :clone, :const_defined?, :const_get, :const_missing,
:const_set, :constants, :define_singleton_method, :display, :dup,
:enum_for, :eql?, :equal?, :extend, :freeze, :frozen?, :gem, :gm,
:hash, :include?, :included_modules, :inspect, :instance_eval,
:instance_exec, :instance_method, :instance_methods, :instance_of?,
:instance_variable_defined?, :instance_variable_get,
:instance_variable_set, :instance_variables, :is_a?, :kind_of?,
:local, :method, :method_defined?, :methods, :mktime, :module_eval,
:module_exec, :name, :new, :nil?, :now, bject_id,
rivate_class_method, rivate_instance_methods,
rivate_method_defined?, rivate_methods,
rotected_instance_methods, rotected_method_defined?,
rotected_methods, ublic_class_method, ublic_instance_method,
ublic_instance_methods, ublic_method, ublic_method_defined?,
ublic_methods, ublic_send, :remove_class_variable, :respond_to?,
:send, :singleton_methods, :superclass, :taint, :tainted?, :tap,
:to_enum, :to_s, :untaint, :utc]
(from an ubuntu box running 1.9.0--but i don't get a parse on 1.8.6 on
ubuntu or mac)

in fact, whytheluckstiff's online ruby terminal at hobix.com *does*
have Time#parse. and you all are using it. any ideas? where did i drop
the ball?

thanks in advance.



On Jan 13, 2008 12:47 PM, Heinrich Piard <(E-Mail Removed)> wrote:
> Daniel Finnie wrote:
> > I would create a time object and then format it how you like.
> >
> > Time.parse(string).strftime(format_string)
> >
> > Look up the docs for Time#strftime to determine the format string.

>
>
> Guys - thanks a lot.
> It works just great!!
>
> Here the snipped:
> ValidDate = File.open("someFile.txt").readlines.to_s.grep(/Not After/)
> #puts 'Certificate is valid ' + ValidDate.to_s
> CertValidDate = Time.parse(ValidDate.to_s).strftime("%Y-%d-%m")
> #puts CertValidDate
>
> Now I can do my comparison with actualDate and CertValidDAte and I am
> able to create an alarm.
>
> Thanks!!!
>
> bye
>
> Henry
> --
> Posted via http://www.ruby-forum.com/.
>
>


 
Reply With Quote
 
Sebastian Hungerecker
Guest
Posts: n/a
 
      01-13-2008
louis wrote:
> sorry to post what might be a moronic question, but i although
> Time.parse shows up in the online core docs, Time.parse isn't a method
> on any machine of mine.


Try requiring time first.
require 'time'

HTH,
Sebastian
--
NP: Arcturus - Alone
Jabber: (E-Mail Removed)
ICQ: 205544826

 
Reply With Quote
 
louis
Guest
Posts: n/a
 
      01-13-2008
that did help a lot! thanks! now i have to find/read more on what's in
the core that needs 'requiring'. thanks again!

> > sorry to post what might be a moronic question, but i although
> > Time.parse shows up in the online core docs, Time.parse isn't a method
> > on any machine of mine.

>
> Try requiring time first.
> require 'time'
>
> HTH,
> Sebastian
> --


 
Reply With Quote
 
Mike McKinney
Guest
Posts: n/a
 
      01-13-2008
[Note: parts of this message were removed to make it a legal post.]

Henry,

should do :

ValidDate = File.readlines('someFile.txt').to_s.grep(/Not After/)

instead of :

ValidDate = File.open("someFile.txt").readlines.to_s.grep(/Not After/)

Sebastian corrected me once... File.open without a block will leave the file
pointer open...

M

On Jan 13, 2008 12:47 PM, Heinrich Piard <(E-Mail Removed)> wrote:

> Daniel Finnie wrote:
> > I would create a time object and then format it how you like.
> >
> > Time.parse(string).strftime(format_string)
> >
> > Look up the docs for Time#strftime to determine the format string.

>
>
> Guys - thanks a lot.
> It works just great!!
>
> Here the snipped:
> ValidDate = File.open("someFile.txt").readlines.to_s.grep(/Not After/)
> #puts 'Certificate is valid ' + ValidDate.to_s
> CertValidDate = Time.parse(ValidDate.to_s).strftime("%Y-%d-%m")
> #puts CertValidDate
>
> Now I can do my comparison with actualDate and CertValidDAte and I am
> able to create an alarm.
>
> Thanks!!!
>
> bye
> Henry
> --
> Posted via http://www.ruby-forum.com/.
>
>


 
Reply With Quote
 
Sebastian Hungerecker
Guest
Posts: n/a
 
      01-13-2008
Mike McKinney wrote:
> should do :
>
> =A0 =A0 ValidDate =3D File.readlines('someFile.txt').to_s.grep(/Not After=

/)

Yes, and leave out the to_s, too. If you want a string use File.read instea=
d=20
of File.readlines. In this case you can use both, though, since String and=
=20
Array both have a grep method. But using readlines to get an array and then=
=20
converting it to string via to_s, doesn't make sense.

HTH,
Sebastian
=2D-=20
NP: Anathema - Cerulean Twilight
Jabber: (E-Mail Removed)
ICQ: 205544826

 
Reply With Quote
 
Heinrich Piard
Guest
Posts: n/a
 
      01-13-2008
Sebastian Hungerecker wrote:
> Mike McKinney wrote:
>> should do :
>>
>> � � ValidDate = File.readlines('someFile.txt').to_s.grep(/Not After/)

>
> Yes, and leave out the to_s, too. If you want a string use File.read
> instead
> of File.readlines. In this case you can use both, though, since String
> and
> Array both have a grep method. But using readlines to get an array and
> then
> converting it to string via to_s, doesn't make sense.
>
> HTH,
> Sebastian


Thanks guys,

I did include those changes in my code.

bye
Henry
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Regualr Expression Puzzle Ken Java 3 02-21-2007 09:47 PM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments