HI,
I have a pretty weird problems with dates.
my objective was to parse some text files and put them into a
database.
the lines of the file are divided with a | and some of the fields are
dates in this format dd.mm.yyyy
now in the parsing a get the system date to skip parsing elements in
the past
@date is the local date created with @date = Time.now.to_date
params[:to] is the string from the file with the date in above format
I did this with a simple
if params && ( params[:to].to_date > @date ) # nie parsujemy
starych
cennikow
Price.create_or_update params
end
on my local enviroment everything works fine but on the remote host i
get an invalid date ArgumentError
ruby version on host
ruby 1.8.6 (2007-06-07 patchlevel 36) [i386-linux]
local
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-linux]
any ideas?
thanks in advance
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 April 2010 15:36, Adam <anlauf.adam-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> HI, > I have a pretty weird problems with dates. > my objective was to parse some text files and put them into a > database. > > the lines of the file are divided with a | and some of the fields are > dates in this format dd.mm.yyyy > now in the parsing a get the system date to skip parsing elements in > the past > @date is the local date created with @date = Time.now.to_date > params[:to] is the string from the file with the date in above format > I did this with a simple > > if params && ( params[:to].to_date > @date ) # nie parsujemy starych > cennikow > Price.create_or_update params > end > > on my local enviroment everything works fine but on the remote host i > get an invalid date ArgumentErrorCatch the error in your code and log or display the params[:to] that is causing it. Then you will likely see the problem. It is risky to convert strings to date without checking validity and taking appropriate action anyway. Colin> > ruby version on host > ruby 1.8.6 (2007-06-07 patchlevel 36) [i386-linux] > local > ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-linux] > > any ideas? > thanks in advance > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
sory for the long absence (holidays) well the params[:to] is a date in this format 27.02.2010, but when i try to log params[:to].to_date I get an error NoMethodError( undefined method''[]'' for nil:NilClass) On 1 Kwi, 07:50, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 1 April 2010 15:36, Adam <anlauf.a...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > HI, > > I have a pretty weird problems withdates. > > my objective was to parse some text files and put them into a > > database. > > > the lines of the file are divided with a | and some of the fields are > >datesin this format dd.mm.yyyy > > now in the parsing a get the system date to skip parsing elements in > > the past > > @date is the local date created with @date = Time.now.to_date > > params[:to] is the string from the file with the date in above format > > I did this with a simple > > > if params && ( params[:to].to_date > @date ) # nie parsujemy starych > > cennikow > > Price.create_or_update params > > end > > > on my local enviroment everything works fine but on the remote host i > > get an invalid date ArgumentError > > Catch the error in your code and log or display the params[:to] that > is causing it. Then you will likely see the problem. It is risky to > convert strings to date without checking validity and taking > appropriate action anyway. > > Colin > > > > > > > ruby version on host > > ruby 1.8.6 (2007-06-07 patchlevel 36) [i386-linux] > > local > > ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-linux] > > > any ideas? > > thanks in advance > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Le 07/04/2010 12:41, Adam a écrit :> sory for the long absence (holidays) > > well the params[:to] is a date in this format 27.02.2010, but when i > try to log params[:to].to_date I get an error > NoMethodError( undefined method''[]'' for nil:NilClass) > > On 1 Kwi, 07:50, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> On 1 April 2010 15:36, Adam <anlauf.a...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> >> >> >> >>> HI, >>> I have a pretty weird problems withdates. >>> my objective was to parse some text files and put them into a >>> database. >>> >> >>> the lines of the file are divided with a | and some of the fields are >>> datesin this format dd.mm.yyyy >>> now in the parsing a get the system date to skip parsing elements in >>> the past >>> @date is the local date created with @date = Time.now.to_date >>> params[:to] is the string from the file with the date in above format >>> I did this with a simple >>> >> >>> if params && ( params[:to].to_date > @date ) # nie parsujemy starych >>> cennikow >>> Price.create_or_update params >>> end >>> >> >>> on my local enviroment everything works fine but on the remote host i >>> get an invalid date ArgumentError >>> >> Catch the error in your code and log or display the params[:to] that >> is causing it. Then you will likely see the problem. It is risky to >> convert strings to date without checking validity and taking >> appropriate action anyway. >> >> Colin >> >> >> >> >> >> >>> ruby version on host >>> ruby 1.8.6 (2007-06-07 patchlevel 36) [i386-linux] >>> local >>> ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-linux] >>> >> >>> any ideas? >>> thanks in advance >>> >> >>> -- >>> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. >>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. >>> >Hi, Assuming params[:to] is a string like "31.12.2007" you should try : Date.parse(params[:to]) -- Aurélien AMILIN -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I''ve tried that too but stille get an argument error with invalid date, i''ve log the dates an they look fine (the format''s ok) ;/ Really hate this kind of errors On 7 Kwi, 03:47, AMILIN Aurélien <aurelien.ami...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Le 07/04/2010 12:41, Adam a crit : > > > > > sory for the long absence (holidays) > > > well the params[:to] is a date in this format 27.02.2010, but when i > > try to log params[:to].to_date I get an error > > NoMethodError( undefined method''[]'' for nil:NilClass) > > > On 1 Kwi, 07:50, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > >> On 1 April 2010 15:36, Adam <anlauf.a...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >>> HI, > >>> I have a pretty weird problems withdates. > >>> my objective was to parse some text files and put them into a > >>> database. > > >>> the lines of the file are divided with a | and some of the fields are > >>> datesin this format dd.mm.yyyy > >>> now in the parsing a get the system date to skip parsing elements in > >>> the past > >>> @date is the local date created with @date = Time.now.to_date > >>> params[:to] is the string from the file with the date in above format > >>> I did this with a simple > > >>> if params && ( params[:to].to_date > @date ) # nie parsujemy starych > >>> cennikow > >>> Price.create_or_update params > >>> end > > >>> on my local enviroment everything works fine but on the remote host i > >>> get an invalid date ArgumentError > > >> Catch the error in your code and log or display the params[:to] that > >> is causing it. Then you will likely see the problem. It is risky to > >> convert strings to date without checking validity and taking > >> appropriate action anyway. > > >> Colin > > >>> ruby version on host > >>> ruby 1.8.6 (2007-06-07 patchlevel 36) [i386-linux] > >>> local > >>> ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-linux] > > >>> any ideas? > >>> thanks in advance > > >>> -- > >>> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > >>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > >>> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >>> For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > Hi, > > Assuming params[:to] is a string like "31.12.2007" > you should try : > > Date.parse(params[:to]) > > -- > Aur lien AMILIN-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I''ll jutr try (for now) to make the dates by spliting the string and extracting every part of it and making a new Date obj. from those parts On 7 Kwi, 04:53, Adam <anlauf.a...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve tried that too but stille get an argument error with invalid > date, i''ve log the dates an they look fine (the format''s ok) ;/ > Really hate this kind of errors > > On 7 Kwi, 03:47, AMILIN Aurélien <aurelien.ami...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Le 07/04/2010 12:41, Adam a crit : > > > > sory for the long absence (holidays) > > > > well the params[:to] is a date in this format 27.02.2010, but when i > > > try to log params[:to].to_date I get an error > > > NoMethodError( undefined method''[]'' for nil:NilClass) > > > > On 1 Kwi, 07:50, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > >> On 1 April 2010 15:36, Adam <anlauf.a...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > >>> HI, > > >>> I have a pretty weird problems withdates. > > >>> my objective was to parse some text files and put them into a > > >>> database. > > > >>> the lines of the file are divided with a | and some of the fields are > > >>> datesin this format dd.mm.yyyy > > >>> now in the parsing a get the system date to skip parsing elements in > > >>> the past > > >>> @date is the local date created with @date = Time.now.to_date > > >>> params[:to] is the string from the file with the date in above format > > >>> I did this with a simple > > > >>> if params && ( params[:to].to_date > @date ) # nie parsujemy starych > > >>> cennikow > > >>> Price.create_or_update params > > >>> end > > > >>> on my local enviroment everything works fine but on the remote host i > > >>> get an invalid date ArgumentError > > > >> Catch the error in your code and log or display the params[:to] that > > >> is causing it. Then you will likely see the problem. It is risky to > > >> convert strings to date without checking validity and taking > > >> appropriate action anyway. > > > >> Colin > > > >>> ruby version on host > > >>> ruby 1.8.6 (2007-06-07 patchlevel 36) [i386-linux] > > >>> local > > >>> ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-linux] > > > >>> any ideas? > > >>> thanks in advance > > > >>> -- > > >>> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > >>> To post to this group, send email to rubyonrails-talk@googlegroups.com. > > >>> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > >>> For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > Hi, > > > Assuming params[:to] is a string like "31.12.2007" > > you should try : > > > Date.parse(params[:to]) > > > -- > > Aur lien AMILIN-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
With strptime you can specify the format:
Date.strptime("07.04.2010", "%d.%m.%Y")
On Apr 7, 2:13 pm, Adam
<anlauf.a...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I''ll jutr try (for now) to make the dates by spliting the string
and
> extracting every part of it and making a new Date obj. from those
> parts
>
> On 7 Kwi, 04:53, Adam
<anlauf.a...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > I''ve tried that too but stille get an argument error with
invalid
> > date, i''ve log the dates an they look fine (the
format''s ok) ;/
> > Really hate this kind of errors
>
> > On 7 Kwi, 03:47, AMILIN Aurélien
<aurelien.ami...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > > Le 07/04/2010 12:41, Adam a crit :
>
> > > > sory for the long absence (holidays)
>
> > > > well the params[:to] is a date in this format 27.02.2010,
but when i
> > > > try to log params[:to].to_date I get an error
> > > > NoMethodError( undefined method''[]'' for
nil:NilClass)
>
> > > > On 1 Kwi, 07:50, Colin Law
<clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:
>
> > > >> On 1 April 2010 15:36, Adam
<anlauf.a...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > > >>> HI,
> > > >>> I have a pretty weird problems withdates.
> > > >>> my objective was to parse some text files and put
them into a
> > > >>> database.
>
> > > >>> the lines of the file are divided with a | and some
of the fields are
> > > >>> datesin this format dd.mm.yyyy
> > > >>> now in the parsing a get the system date to skip
parsing elements in
> > > >>> the past
> > > >>> @date is the local date created with @date =
Time.now.to_date
> > > >>> params[:to] is the string from the file with the
date in above format
> > > >>> I did this with a simple
>
> > > >>> if params && ( params[:to].to_date >
@date ) # nie parsujemy starych
> > > >>> cennikow
> > > >>> Price.create_or_update params
> > > >>> end
>
> > > >>> on my local enviroment everything works fine but on
the remote host i
> > > >>> get an invalid date ArgumentError
>
> > > >> Catch the error in your code and log or display the
params[:to] that
> > > >> is causing it. Then you will likely see the problem.
It is risky to
> > > >> convert strings to date without checking validity and
taking
> > > >> appropriate action anyway.
>
> > > >> Colin
>
> > > >>> ruby version on host
> > > >>> ruby 1.8.6 (2007-06-07 patchlevel 36) [i386-linux]
> > > >>> local
> > > >>> ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-linux]
>
> > > >>> any ideas?
> > > >>> thanks in advance
>
> > > >>> --
> > > >>> You received this message because you are subscribed
to the Google Groups "Ruby on Rails: Talk" group.
> > > >>> To post to this group, send email to
rubyonrails-talk@googlegroups.com.
> > > >>> To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > > >>> For more options, visit this group
athttp://groups.google.com/group/rubyonrails-talk?hl=en.
>
> > > Hi,
>
> > > Assuming params[:to] is a string like "31.12.2007"
> > > you should try :
>
> > > Date.parse(params[:to])
>
> > > --
> > > Aur lien AMILIN
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.