misiek
(misiek)
24 January 2006 16:43
1
hi
problem is ....
I got date @start and date @stop as a date and I can display like
@start = Thu Jan 19 00:00:00 CST 2006
@stop = Tue Jan 21 00:00:00 CST 2006
how to split up this days and put to array ?
array[] = "Thu Jan 19 00:00:00 CST 2006
Wed Jan 20 00:00:00 CST 2006
Tue Jan 21 00:00:00 CST 2006"
is there some function which can do that ?
thanks for help
Robert
(Robert)
24 January 2006 16:53
2
misiek wrote:
hi
problem is ....
I got date @start and date @stop as a date and I can display like
@start = Thu Jan 19 00:00:00 CST 2006
@stop = Tue Jan 21 00:00:00 CST 2006
This is not valid Ruby code. What types are these objects?
how to split up this days and put to array ?
array = "Thu Jan 19 00:00:00 CST 2006
Wed Jan 20 00:00:00 CST 2006
Tue Jan 21 00:00:00 CST 2006"
You assign a string but you seem to want an array. Also, you don't seem
to want to split but to append.
# split at whitespace
array = @start.to_s.split /\s+/
# split into array, works for Time
array = @start.to_a
# put into array
array = [@start , @stop ]
# concatenate
array = "#{@start }\n#{@stop }"
is there some function which can do that ?
If you tells us what you actually want, we might be able to come up with
an answer.
Cheers
robert
misiek
(misiek)
24 January 2006 17:23
3
Robert Klemme wrote:
misiek wrote:
hi
problem is ....
I got date @start and date @stop as a date and I can display like
@start = Thu Jan 19 00:00:00 CST 2006
@stop = Tue Jan 21 00:00:00 CST 2006
This is not valid Ruby code. What types are these objects?
how to split up this days and put to array ?
array = "Thu Jan 19 00:00:00 CST 2006
Wed Jan 20 00:00:00 CST 2006
Tue Jan 21 00:00:00 CST 2006"
You assign a string but you seem to want an array. Also, you don't seem
to want to split but to append.
# split at whitespace
array = @start.to_s.split /\s+/
# split into array, works for Time
array = @start.to_a
# put into array
array = [@start , @stop ]
# concatenate
array = "#{@start }\n#{@stop }"
is there some function which can do that ?
If you tells us what you actually want, we might be able to come up with
an answer.
Cheers
robert
thank you for answer .
from FORM I can select days, FROM - TO
like from Monday to Friday
exanmple:
from 2006-01-20 to 2006-01-24
and than I need to put each day to database as five days like
2006-01-20
2006-01-21
2006-01-22
2006-01-23
2006-01-24
so first I need to put each day to array and that in loop put each day to database.
this is what I want
thanks for help
11110
(王东)
24 January 2006 18:28
4
def toSecond(stime)
atime=stime.split("-")
return Time.local(atime[0],atime[1],atime[2]).to_i
end
@start = "2006-01-20"
@stop = "2006-01-24"
array=Array.new
toSecond(@start ).step(toSecond(@stop ),86400) do |t|
array.push(Time.at (t).strftime("%Y-%m-%d"))
end
puts array
# Is this ok?
Robert_K1
(Robert K.)
24 January 2006 18:58
5
Now we're cooking. How's that?
require 'date'
# fetch start and end date from somewhere
start=Date.today
endd=start+30
d=start
while d < endd
puts d
d += 5
end
robert
···
2006/1/24, misiek <michaelaugustyniak@gazeta.pl>:
from FORM I can select days, FROM - TO
like from Monday to Friday
exanmple:
from 2006-01-20 to 2006-01-24
and than I need to put each day to database as five days like
2006-01-20
2006-01-21
2006-01-22
2006-01-23
2006-01-24
so first I need to put each day to array and that in loop put each day
to database.
this is what I want
thanks for help
--
Have a look: http://www.flickr.com/photos/fussel-foto/
Sky_Yin
(Sky Yin)
24 January 2006 19:05
6
Range can help you. Example:
require 'date'
days = (Date.new(2006,1,20)..Date.new(2006,1,24)).to_a
days.each {|date| puts date}
=>2006-01-20
=>2006-01-21
=>2006-01-22
=>2006-01-23
=>2006-01-24
:^)
···
On 1/24/06, misiek <michaelaugustyniak@gazeta.pl> wrote:
Robert Klemme wrote:
> misiek wrote:
>
>>hi
>>
>>problem is ....
>>
>>I got date @start and date @stop as a date and I can display like
>>
>>@start = Thu Jan 19 00:00:00 CST 2006
>>@stop = Tue Jan 21 00:00:00 CST 2006
>
>
> This is not valid Ruby code. What types are these objects?
>
>
>>how to split up this days and put to array ?
>>
>>array = "Thu Jan 19 00:00:00 CST 2006
>>Wed Jan 20 00:00:00 CST 2006
>>Tue Jan 21 00:00:00 CST 2006"
>
>
> You assign a string but you seem to want an array. Also, you don't seem
> to want to split but to append.
>
> # split at whitespace
> array = @start.to_s.split /\s+/
>
> # split into array, works for Time
> array = @start.to_a
>
> # put into array
> array = [@start , @stop ]
>
> # concatenate
> array = "#{@start }\n#{@stop }"
>
>
>>is there some function which can do that ?
>
>
> If you tells us what you actually want, we might be able to come up with
> an answer.
>
> Cheers
>
> robert
>
thank you for answer .
from FORM I can select days, FROM - TO
like from Monday to Friday
exanmple:
from 2006-01-20 to 2006-01-24
and than I need to put each day to database as five days like
2006-01-20
2006-01-21
2006-01-22
2006-01-23
2006-01-24
so first I need to put each day to array and that in loop put each day
to database.
this is what I want
thanks for help
--
Blog >>> http://spaces.msn.com/members/skyincookoo
misiek
(misiek)
24 January 2006 21:33
7
Sky Yin wrote:
Range can help you. Example:
require 'date'
days = (Date.new(2006,1,20)..Date.new(2006,1,24)).to_a
days.each {|date| puts date}
=>2006-01-20
=>2006-01-21
=>2006-01-22
=>2006-01-23
=>2006-01-24
:^)
this is super but why when I will put 2006,3,2 into variable
like @start = "2006,1,3" and @stop = "2006,1,4" does not work ?
days = (Date.new(@start )..Date.new(@stop )).to_a
undefined method `-' for "2006,1,3":String
Sky_Yin
(Sky Yin)
24 January 2006 22:19
8
It's easy to transfer the string "year, month, day" to the parameter
format that meets the requirement of Date.new(year, month, day) :
date_start = @start.split (',').map {|x|, x.to_i}
date_stop = @stop.split (',').map {|x|, x.to_i}
days = (Date.new(@start )..Date.new(@stop )).to_a
Still elegant?
···
On 1/24/06, misiek <michaelaugustyniak@gazeta.pl> wrote:
Sky Yin wrote:
> Range can help you. Example:
>
>
>>>require 'date'
>>>days = (Date.new(2006,1,20)..Date.new(2006,1,24)).to_a
>>>days.each {|date| puts date}
>
> =>2006-01-20
> =>2006-01-21
> =>2006-01-22
> =>2006-01-23
> =>2006-01-24
>
> :^)
>
this is super but why when I will put 2006,3,2 into variable
like @start = "2006,1,3" and @stop = "2006,1,4" does not work ?
days = (Date.new(@start )..Date.new(@stop )).to_a
undefined method `-' for "2006,1,3":String
--
Blog >>> http://spaces.msn.com/members/skyincookoo
Sky_Yin
(Sky Yin)
24 January 2006 22:21
9
oops, the last line should be:
days = (Date.new(date_start)..Date.new(date_stop)).to_a
···
On 1/24/06, Sky Yin <sky.yin@gmail.com> wrote:
It's easy to transfer the string "year, month, day" to the parameter
format that meets the requirement of Date.new(year, month, day) :
date_start = @start.split (',').map {|x|, x.to_i}
date_stop = @stop.split (',').map {|x|, x.to_i}
days = (Date.new(@start )..Date.new(@stop )).to_a
Still elegant?
On 1/24/06, misiek <michaelaugustyniak@gazeta.pl> wrote:
> Sky Yin wrote:
> > Range can help you. Example:
> >
> >
> >>>require 'date'
> >>>days = (Date.new(2006,1,20)..Date.new(2006,1,24)).to_a
> >>>days.each {|date| puts date}
> >
> > =>2006-01-20
> > =>2006-01-21
> > =>2006-01-22
> > =>2006-01-23
> > =>2006-01-24
> >
> > :^)
> >
>
> this is super but why when I will put 2006,3,2 into variable
> like @start = "2006,1,3" and @stop = "2006,1,4" does not work ?
> days = (Date.new(@start )..Date.new(@stop )).to_a
>
>
> undefined method `-' for "2006,1,3":String
>
>
--
Blog >>> http://spaces.msn.com/members/skyincookoo
--
Blog >>> http://spaces.msn.com/members/skyincookoo
misiek
(misiek)
24 January 2006 23:13
10
Sky Yin wrote:
oops, the last line should be:
days = (Date.new(date_start)..Date.new(date_stop)).to_a
It's easy to transfer the string "year, month, day" to the parameter
format that meets the requirement of Date.new(year, month, day) :
date_start = @start.split (',').map {|x|, x.to_i}
date_stop = @stop.split (',').map {|x|, x.to_i}
days = (Date.new(@start )..Date.new(@stop )).to_a
Still elegant?
I got like
@start = @params ['start']['year'].to_s + "," + @params ['start']['month'].to_s + "," + @params ['start']['day'].to_s
@stop = @params ['stop']['year'].to_s + "," + @params ['stop']['month'].to_s + "," + @params ['stop']['day'].to_s
and I try to put to
days = (Date.new(@start )..Date.new(@stop )).to_a
still got this error undefined method `-' for "2006,1,3":String
BTW what is "x" => date_start = @start.split (',').map {|x|, x.to_i} ?
^ ^
or is going about (',') ? hmm
because is error
../script/../config/../app/controllers/hour_controller.rb:178: parse error, unexpected ','
date_start = @start.split (',').map {|x|, x.to_i}
^
···
On 1/24/06, Sky Yin <sky.yin@gmail.com> wrote:
misiek
(misiek)
24 January 2006 23:18
11
ups to put to
date_start = @start.split (',').map {|x|, x.to_i}
I try format like this
@start = Time.local(@params ['start']['year'],@params ['start']['month'],@params ['start']['day'])
the same error
misiek
(misiek)
24 January 2006 23:18
12
I removed , from date_start = @start.split (',').map {|x| x.to_i}
^
now got
private method `split' called for Tue Jan 24 00:00:00 CST 2006:Time
Sky_Yin
(Sky Yin)
24 January 2006 23:35
13
sry, I copied a wrong part of my own code. What I tried to do is to
split the string "year, month, day" into 3 integers and store in an
array [year, month, day], then create Date objects from the arrays.
def new_date(date)
Date.new(date[0], date[1], date[2])
end
date_start = @start.split (',').map {|x|, x.to_i}
date_stop = @stop.split (',').map {|x|, x.to_i}
days = (new_date(date_start)..new_date(date_stop)).to_a
This should work now.
···
On 1/24/06, misiek <michaelaugustyniak@gazeta.pl> wrote:
I removed , from date_start = @start.split (',').map {|x| x.to_i}
^
now got
private method `split' called for Tue Jan 24 00:00:00 CST 2006:Time
--
Blog >>> http://spaces.msn.com/members/skyincookoo