Re: How to generate random dates

2008-10-24 Thread Hiro Protagonist
Andrey,

Thank you very much. *reference bookmarked*
I didn't know about the zero-bounded month method. That explains it.

Thanks again.
hiro
On Fri, 2008-10-24 at 11:51 +0400, Andrey Beznogov wrote:
> Hi,
> 
> please read the reference for javascript Date object - for example here:
> 
> https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date
> 
> As written there, for the Date object "Months: 0 (January) to 11
> (December)" - so getMonths() returns the number between 0 and 11 - and
> 9 corresponds to October and not September.
> 
> Javascript should not have a problem with long numbers if the date is
> between 1900 and 2100. So the following script
> 
> var startMillis = new Date(1900,0,1).getTime(); //Get millis for
> January 1st 1900
> var endMillis = new Date(2100,0,1).getTime(); //Get millis for January 1st 
> 2100
> var randomDate = new Date(startMillis +
> Math.random()*(endMillis-startMillis)); //new Date() with millis set
> to random value between startMillis and endMillis
> randomDate.toUTCString(); //Output UTC string for randomDate
> 
> should work fine.
> 
> Regards,
> Andrey
> 
> On Thu, Oct 23, 2008 at 10:01 PM, Hiro Protagonist
> <[EMAIL PROTECTED]> wrote:
> > Laurent,
> >
> > I think Javascript has a problem with the long numbers...
> > I tried your suggestion but the problem is that javascript cant handle
> > the longs.
> >
> > My other attempt:
> >
> > ${__javaScript(var mydate=new Date();
> > mydate.setDate(mydate.getDate()-${__Random(1,14)});
> > mydate.getDate()+"/"+mydate.getMonth()+"/"+mydate.getFullYear();)}
> >
> > also failed, since it always shows me the month of September (9) even
> > though we are obviously in October and the number of days subtracted
> > from today should be between 1 and 14
> > Any ideas where I'm going wrong ?
> >
> > Thanks !
> >
> > hiro
> >
> > On Thu, 2008-10-23 at 17:14 +0200, Laurent Perez wrote:
> >> shameless blog copy and paste, looks good enough :
> >>
> >> http://blogs.circlesource.com/2008/07/17/generating-random-datetime-between-2-different-datestimestamps-in-java/
> >>
> >> (java code, if it does not adapt under javascript, you could use a
> >> beanshell script within jmeter)
> >>
> >> laurent
> >>
> >> 2008/10/23 Hiro Protagonist <[EMAIL PROTECTED]>:
> >> > Andrey, All,
> >> >
> >> > I can't seem to get it to generate random dates that have to lie between
> >> > two date boundaries. I've tried sth like this (hack !!):
> >> >
> >> > ${__javaScript(
> >> > var today_date=new Date();
> >> > var old_date=new Date();
> >> > old_date.setDate(today_date.getDate()-5);
> >> > var old_date_int = old_date.getTime();
> >> > var today_date_int = today_date.getTime();
> >> > var random_date_int=old_date_int
> >> > +(Math.random()*(today_date_int-old_date_int));
> >> > random_date_int.toUTCString();)}
> >> >
> >> > but when I use this it doesn't evaulate. Does anyone have anything
> >> > 'out-of-the-box' that works ?
> >> >
> >> > TIA
> >> > hiro
> >> >
> >> > On Thu, 2008-10-23 at 16:05 +0400, Andrey Beznogov wrote:
> >> >> Hi,
> >> >>
> >> >> the best way would be probably randomizing the Time part (the number
> >> >> of milliseconds since 1970/01/01) of the Date(). For example in
> >> >> javascript
> >> >>
> >> >> var mydate=new Date();
> >> >> mydate.setTime(mydate.getTime()*Math.random());
> >> >> mydate.toUTCString();
> >> >>
> >> >> will output a date string in UTC format (like "Sat, 19 Jan 1985
> >> >> 06:22:28 GMT") for a date between now and 1970/01/01.
> >> >>
> >> >> Regards,
> >> >> Andrey
> >> >>
> >> >> On Thu, Oct 23, 2008 at 3:47 PM, Hiro Protagonist
> >> >> <[EMAIL PROTECTED]> wrote:
> >> >> > Hi team,
> >> >> >
> >> >> > I need to generate random dates in JMeter. I know that by merely using
> >> >> > the random function and then 'building' the date string I can get 90% 
> >> >> > of
> >> >> > the way there - however, in order no to risk faulty dates, I always 
> >> >> > lose
> >> >> > out on dates after the 28th.
> >> >> > The obvious problem here is the interdependency between the months and
> >> >> > their respective number of days.
> >> >> > Does anyone know of a quick and easy solution ?
> >> >> >
> >> >> > Thanks !
> >> >> >
> >> >> > hiro
> >> >> >
> >> >> >
> >> >> > -
> >> >> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> >> > For additional commands, e-mail: [EMAIL PROTECTED]
> >> >> >
> >> >> >
> >> >>
> >> >>
> >> >>
> >> >
> >> >
> >> > -
> >> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> > For additional commands, e-mail: [EMAIL PROTECTED]
> >> >
> >> >
> >>
> >>
> >>
> >
> >
> > -
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> 
> 
> 


-
To unsubscribe, e-mail

Re: How to generate random dates

2008-10-24 Thread Andrey Beznogov
Hi,

please read the reference for javascript Date object - for example here:

https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date

As written there, for the Date object "Months: 0 (January) to 11
(December)" - so getMonths() returns the number between 0 and 11 - and
9 corresponds to October and not September.

Javascript should not have a problem with long numbers if the date is
between 1900 and 2100. So the following script

var startMillis = new Date(1900,0,1).getTime(); //Get millis for
January 1st 1900
var endMillis = new Date(2100,0,1).getTime(); //Get millis for January 1st 2100
var randomDate = new Date(startMillis +
Math.random()*(endMillis-startMillis)); //new Date() with millis set
to random value between startMillis and endMillis
randomDate.toUTCString(); //Output UTC string for randomDate

should work fine.

Regards,
Andrey

On Thu, Oct 23, 2008 at 10:01 PM, Hiro Protagonist
<[EMAIL PROTECTED]> wrote:
> Laurent,
>
> I think Javascript has a problem with the long numbers...
> I tried your suggestion but the problem is that javascript cant handle
> the longs.
>
> My other attempt:
>
> ${__javaScript(var mydate=new Date();
> mydate.setDate(mydate.getDate()-${__Random(1,14)});
> mydate.getDate()+"/"+mydate.getMonth()+"/"+mydate.getFullYear();)}
>
> also failed, since it always shows me the month of September (9) even
> though we are obviously in October and the number of days subtracted
> from today should be between 1 and 14
> Any ideas where I'm going wrong ?
>
> Thanks !
>
> hiro
>
> On Thu, 2008-10-23 at 17:14 +0200, Laurent Perez wrote:
>> shameless blog copy and paste, looks good enough :
>>
>> http://blogs.circlesource.com/2008/07/17/generating-random-datetime-between-2-different-datestimestamps-in-java/
>>
>> (java code, if it does not adapt under javascript, you could use a
>> beanshell script within jmeter)
>>
>> laurent
>>
>> 2008/10/23 Hiro Protagonist <[EMAIL PROTECTED]>:
>> > Andrey, All,
>> >
>> > I can't seem to get it to generate random dates that have to lie between
>> > two date boundaries. I've tried sth like this (hack !!):
>> >
>> > ${__javaScript(
>> > var today_date=new Date();
>> > var old_date=new Date();
>> > old_date.setDate(today_date.getDate()-5);
>> > var old_date_int = old_date.getTime();
>> > var today_date_int = today_date.getTime();
>> > var random_date_int=old_date_int
>> > +(Math.random()*(today_date_int-old_date_int));
>> > random_date_int.toUTCString();)}
>> >
>> > but when I use this it doesn't evaulate. Does anyone have anything
>> > 'out-of-the-box' that works ?
>> >
>> > TIA
>> > hiro
>> >
>> > On Thu, 2008-10-23 at 16:05 +0400, Andrey Beznogov wrote:
>> >> Hi,
>> >>
>> >> the best way would be probably randomizing the Time part (the number
>> >> of milliseconds since 1970/01/01) of the Date(). For example in
>> >> javascript
>> >>
>> >> var mydate=new Date();
>> >> mydate.setTime(mydate.getTime()*Math.random());
>> >> mydate.toUTCString();
>> >>
>> >> will output a date string in UTC format (like "Sat, 19 Jan 1985
>> >> 06:22:28 GMT") for a date between now and 1970/01/01.
>> >>
>> >> Regards,
>> >> Andrey
>> >>
>> >> On Thu, Oct 23, 2008 at 3:47 PM, Hiro Protagonist
>> >> <[EMAIL PROTECTED]> wrote:
>> >> > Hi team,
>> >> >
>> >> > I need to generate random dates in JMeter. I know that by merely using
>> >> > the random function and then 'building' the date string I can get 90% of
>> >> > the way there - however, in order no to risk faulty dates, I always lose
>> >> > out on dates after the 28th.
>> >> > The obvious problem here is the interdependency between the months and
>> >> > their respective number of days.
>> >> > Does anyone know of a quick and easy solution ?
>> >> >
>> >> > Thanks !
>> >> >
>> >> > hiro
>> >> >
>> >> >
>> >> > -
>> >> > To unsubscribe, e-mail: [EMAIL PROTECTED]
>> >> > For additional commands, e-mail: [EMAIL PROTECTED]
>> >> >
>> >> >
>> >>
>> >>
>> >>
>> >
>> >
>> > -
>> > To unsubscribe, e-mail: [EMAIL PROTECTED]
>> > For additional commands, e-mail: [EMAIL PROTECTED]
>> >
>> >
>>
>>
>>
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



-- 
diem perdidi

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to generate random dates

2008-10-23 Thread Hiro Protagonist
Laurent,

I think Javascript has a problem with the long numbers...
I tried your suggestion but the problem is that javascript cant handle
the longs.

My other attempt:

${__javaScript(var mydate=new Date();
mydate.setDate(mydate.getDate()-${__Random(1,14)});
mydate.getDate()+"/"+mydate.getMonth()+"/"+mydate.getFullYear();)}

also failed, since it always shows me the month of September (9) even
though we are obviously in October and the number of days subtracted
from today should be between 1 and 14
Any ideas where I'm going wrong ?

Thanks !

hiro

On Thu, 2008-10-23 at 17:14 +0200, Laurent Perez wrote:
> shameless blog copy and paste, looks good enough :
> 
> http://blogs.circlesource.com/2008/07/17/generating-random-datetime-between-2-different-datestimestamps-in-java/
> 
> (java code, if it does not adapt under javascript, you could use a
> beanshell script within jmeter)
> 
> laurent
> 
> 2008/10/23 Hiro Protagonist <[EMAIL PROTECTED]>:
> > Andrey, All,
> >
> > I can't seem to get it to generate random dates that have to lie between
> > two date boundaries. I've tried sth like this (hack !!):
> >
> > ${__javaScript(
> > var today_date=new Date();
> > var old_date=new Date();
> > old_date.setDate(today_date.getDate()-5);
> > var old_date_int = old_date.getTime();
> > var today_date_int = today_date.getTime();
> > var random_date_int=old_date_int
> > +(Math.random()*(today_date_int-old_date_int));
> > random_date_int.toUTCString();)}
> >
> > but when I use this it doesn't evaulate. Does anyone have anything
> > 'out-of-the-box' that works ?
> >
> > TIA
> > hiro
> >
> > On Thu, 2008-10-23 at 16:05 +0400, Andrey Beznogov wrote:
> >> Hi,
> >>
> >> the best way would be probably randomizing the Time part (the number
> >> of milliseconds since 1970/01/01) of the Date(). For example in
> >> javascript
> >>
> >> var mydate=new Date();
> >> mydate.setTime(mydate.getTime()*Math.random());
> >> mydate.toUTCString();
> >>
> >> will output a date string in UTC format (like "Sat, 19 Jan 1985
> >> 06:22:28 GMT") for a date between now and 1970/01/01.
> >>
> >> Regards,
> >> Andrey
> >>
> >> On Thu, Oct 23, 2008 at 3:47 PM, Hiro Protagonist
> >> <[EMAIL PROTECTED]> wrote:
> >> > Hi team,
> >> >
> >> > I need to generate random dates in JMeter. I know that by merely using
> >> > the random function and then 'building' the date string I can get 90% of
> >> > the way there - however, in order no to risk faulty dates, I always lose
> >> > out on dates after the 28th.
> >> > The obvious problem here is the interdependency between the months and
> >> > their respective number of days.
> >> > Does anyone know of a quick and easy solution ?
> >> >
> >> > Thanks !
> >> >
> >> > hiro
> >> >
> >> >
> >> > -
> >> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> > For additional commands, e-mail: [EMAIL PROTECTED]
> >> >
> >> >
> >>
> >>
> >>
> >
> >
> > -
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> 
> 
> 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to generate random dates

2008-10-23 Thread Laurent Perez
shameless blog copy and paste, looks good enough :

http://blogs.circlesource.com/2008/07/17/generating-random-datetime-between-2-different-datestimestamps-in-java/

(java code, if it does not adapt under javascript, you could use a
beanshell script within jmeter)

laurent

2008/10/23 Hiro Protagonist <[EMAIL PROTECTED]>:
> Andrey, All,
>
> I can't seem to get it to generate random dates that have to lie between
> two date boundaries. I've tried sth like this (hack !!):
>
> ${__javaScript(
> var today_date=new Date();
> var old_date=new Date();
> old_date.setDate(today_date.getDate()-5);
> var old_date_int = old_date.getTime();
> var today_date_int = today_date.getTime();
> var random_date_int=old_date_int
> +(Math.random()*(today_date_int-old_date_int));
> random_date_int.toUTCString();)}
>
> but when I use this it doesn't evaulate. Does anyone have anything
> 'out-of-the-box' that works ?
>
> TIA
> hiro
>
> On Thu, 2008-10-23 at 16:05 +0400, Andrey Beznogov wrote:
>> Hi,
>>
>> the best way would be probably randomizing the Time part (the number
>> of milliseconds since 1970/01/01) of the Date(). For example in
>> javascript
>>
>> var mydate=new Date();
>> mydate.setTime(mydate.getTime()*Math.random());
>> mydate.toUTCString();
>>
>> will output a date string in UTC format (like "Sat, 19 Jan 1985
>> 06:22:28 GMT") for a date between now and 1970/01/01.
>>
>> Regards,
>> Andrey
>>
>> On Thu, Oct 23, 2008 at 3:47 PM, Hiro Protagonist
>> <[EMAIL PROTECTED]> wrote:
>> > Hi team,
>> >
>> > I need to generate random dates in JMeter. I know that by merely using
>> > the random function and then 'building' the date string I can get 90% of
>> > the way there - however, in order no to risk faulty dates, I always lose
>> > out on dates after the 28th.
>> > The obvious problem here is the interdependency between the months and
>> > their respective number of days.
>> > Does anyone know of a quick and easy solution ?
>> >
>> > Thanks !
>> >
>> > hiro
>> >
>> >
>> > -
>> > To unsubscribe, e-mail: [EMAIL PROTECTED]
>> > For additional commands, e-mail: [EMAIL PROTECTED]
>> >
>> >
>>
>>
>>
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



-- 
http://in-pocket.blogspot.com";>http://in-pocket.blogspot.com
- Mobile world, technology and more

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to generate random dates

2008-10-23 Thread Hiro Protagonist
Andrey, All,

I can't seem to get it to generate random dates that have to lie between
two date boundaries. I've tried sth like this (hack !!):

${__javaScript(
var today_date=new Date(); 
var old_date=new Date(); 
old_date.setDate(today_date.getDate()-5); 
var old_date_int = old_date.getTime(); 
var today_date_int = today_date.getTime(); 
var random_date_int=old_date_int
+(Math.random()*(today_date_int-old_date_int));
random_date_int.toUTCString();)}

but when I use this it doesn't evaulate. Does anyone have anything
'out-of-the-box' that works ?

TIA
hiro

On Thu, 2008-10-23 at 16:05 +0400, Andrey Beznogov wrote:
> Hi,
> 
> the best way would be probably randomizing the Time part (the number
> of milliseconds since 1970/01/01) of the Date(). For example in
> javascript
> 
> var mydate=new Date();
> mydate.setTime(mydate.getTime()*Math.random());
> mydate.toUTCString();
> 
> will output a date string in UTC format (like "Sat, 19 Jan 1985
> 06:22:28 GMT") for a date between now and 1970/01/01.
> 
> Regards,
> Andrey
> 
> On Thu, Oct 23, 2008 at 3:47 PM, Hiro Protagonist
> <[EMAIL PROTECTED]> wrote:
> > Hi team,
> >
> > I need to generate random dates in JMeter. I know that by merely using
> > the random function and then 'building' the date string I can get 90% of
> > the way there - however, in order no to risk faulty dates, I always lose
> > out on dates after the 28th.
> > The obvious problem here is the interdependency between the months and
> > their respective number of days.
> > Does anyone know of a quick and easy solution ?
> >
> > Thanks !
> >
> > hiro
> >
> >
> > -
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> 
> 
> 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to generate random dates

2008-10-23 Thread Hiro Protagonist
Hi Andrey,

Thanks for your response. I tried it, and it works very well ! 
(Now restricting it to a random date within a date range...)

hiro

On Thu, 2008-10-23 at 16:05 +0400, Andrey Beznogov wrote:
> Hi,
> 
> the best way would be probably randomizing the Time part (the number
> of milliseconds since 1970/01/01) of the Date(). For example in
> javascript
> 
> var mydate=new Date();
> mydate.setTime(mydate.getTime()*Math.random());
> mydate.toUTCString();
> 
> will output a date string in UTC format (like "Sat, 19 Jan 1985
> 06:22:28 GMT") for a date between now and 1970/01/01.
> 
> Regards,
> Andrey
> 
> On Thu, Oct 23, 2008 at 3:47 PM, Hiro Protagonist
> <[EMAIL PROTECTED]> wrote:
> > Hi team,
> >
> > I need to generate random dates in JMeter. I know that by merely using
> > the random function and then 'building' the date string I can get 90% of
> > the way there - however, in order no to risk faulty dates, I always lose
> > out on dates after the 28th.
> > The obvious problem here is the interdependency between the months and
> > their respective number of days.
> > Does anyone know of a quick and easy solution ?
> >
> > Thanks !
> >
> > hiro
> >
> >
> > -
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> 
> 
> 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to generate random dates

2008-10-23 Thread Andrey Beznogov
Hi,

the best way would be probably randomizing the Time part (the number
of milliseconds since 1970/01/01) of the Date(). For example in
javascript

var mydate=new Date();
mydate.setTime(mydate.getTime()*Math.random());
mydate.toUTCString();

will output a date string in UTC format (like "Sat, 19 Jan 1985
06:22:28 GMT") for a date between now and 1970/01/01.

Regards,
Andrey

On Thu, Oct 23, 2008 at 3:47 PM, Hiro Protagonist
<[EMAIL PROTECTED]> wrote:
> Hi team,
>
> I need to generate random dates in JMeter. I know that by merely using
> the random function and then 'building' the date string I can get 90% of
> the way there - however, in order no to risk faulty dates, I always lose
> out on dates after the 28th.
> The obvious problem here is the interdependency between the months and
> their respective number of days.
> Does anyone know of a quick and easy solution ?
>
> Thanks !
>
> hiro
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



-- 
diem perdidi

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



How to generate random dates

2008-10-23 Thread Hiro Protagonist
Hi team,

I need to generate random dates in JMeter. I know that by merely using
the random function and then 'building' the date string I can get 90% of
the way there - however, in order no to risk faulty dates, I always lose
out on dates after the 28th.
The obvious problem here is the interdependency between the months and
their respective number of days.
Does anyone know of a quick and easy solution ?

Thanks !

hiro


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]