How to use faker.date.between faker.js - javascript

I want to generate some dates between two fixed values, but I don't know how to
use faker.date.between to achieve that.
the example in faker js demo is just giving a null value.

Not sure when did they update wiki, but they do have a working sample for date.between now
faker.date.between('2015-01-01', '2015-01-05');

Their code from Github shows:
self.between = function (from, to) {
var fromMilli = Date.parse(from);
var dateOffset = faker.random.number(Date.parse(to) - fromMilli);
var newDate = new Date(fromMilli + dateOffset);
return newDate;
};
And I don't know how you're using it, or why it's not working on their example.... But this should give you some direction, at least.
If this does not help you, or is still producing an undesired result, I would open an issue up on their github.

Related

Why isn't my bulk variable assignment working as expected?

I am trying to make it small (short), but it is not happening, please tell me where I am wrong. And where I am wrong, you correct there...
var set1 = document.querySelector(".get1");
var set2 = document.querySelector(".get2");
var set3 = document.querySelector(".get3");
var set4 = document.querySelector(".get4");
to..
var ("[set1],[set2],[set3],[set4]")
= document.querySelector("[.get1],[.get2],[.get3],[.get4]")
but it's not work
First code is work very well but the second code which is a shortened form of the first code is not working
You will have to use .map() and destrcutring to transform your given array and then assign it to individual values. You can do this:
let [var1,var2,var3,var4] =
['.get1','.get2','.get3','.get4'].map(x => document.querySelector(x));
But as mentioned your code is fine the way it is. It is simpler and easier to understand.

Chaining Read-Writes with Office-JS

I am having a problem working out how to chain syncs in Office JS - I think I have to do one sync to read the values then another sync to write them back - must be simple but I can't find a chaining example.
Basically I am trying to code the equivalent of this VBA code which does a read and a write via an array
Application.ScreenUpdating = False
d1 = MicroTimer
Set rng1 = Worksheets("Sheet1").Range("A1:A1000")
Set rng2 = Worksheets("Sheet1").Range("D1:D1000")
var = rng1.Value2
rng2.Value2 = var
d2 = (MicroTimer - d1) * 1000
MsgBox d2
or even simpler
Worksheets("Sheet1").Range("D1:D1000").Value2=Worksheets("Sheet1").Range("A1:A1000").Value2
To copy the values from one range to another, you can use the following code:
Excel.run(function(context) {
var range1 = context.workbook.worksheets.getItem("Sheet1").getRange("A1:A1000").load('values');
return context.sync()
.then(() => {
var range2 = context.workbook.worksheets.getItem("Sheet1").getRange("D1:D1000");
range2.values = range1.values;
return context.sync();
});
});
You can use the Range-Class OfficeJS gives you.
Here is the full doc: https://dev.office.com/reference/add-ins/excel/range (Also have a look at the examples given there)
To copy the Range, you need to create both ranges and copy the .values[][] from the source to the dest.
For how to copy a two-dimensional array (in this case: values[][]), you should use google.
To Determine the time, you can use the Date()-Class Java gives you.

Compare Current Date and Time to input of type DateTime

I have googled a bit and could not find an answer. So here is my situation.
I have an input of type dateTime. I want to compare the value picked (mobile app for blackberry) to the current date and time. if the selected date is in the future (bigger than date now) I have to show a simple error message. This is all done when the user tries to save the data.
I have tried code like this, but was unsucessfull.
var dateOfIncident = $('#AccidentDetailsDate').val();
var dateNow = Date.now();
if(dateNow > dateOfIncident)
{
// do my stuffs :)
}
This does not work... It passes that validation. I am very new to javascript myself. Any help would be greatly appreciated. I googled and could not find a solution that does not use anything fancy. I need to do it in javascript.
Thanks in advance.
Try this:
var dateOfIncident = new Date($('#AccidentDetailsDate').val()); // or Date.parse(...)
var dateNow = new Date(); // or Date.now()
if(dateNow > dateOfIncident)
{
// do your stuffs...
}
However, if this works may depend on what format your date-string is! You may want to consider this post as well.

How to call studentt method of jstat to get result?

I have a question about how to use the distribution functions within the jstat library. Specifically, I am focused on studentt.
I've tried this:
var alphaLevel = 0.05;
var degreesOfFreedom = 18;
// the answer I want to get is 2.100922
tStat = jStat.studentt(alphaLevel,degreesOfFreedom);
// but all that is returned is an object with
// members _a,_b,_c (_a=alphaLevel, _b=degreesOfFreedom,_c=undefined).
As explained on the jstat github site, there is a difference between static and instance functions. However, it is above my experience with javascript as to how to do this.
Can anyone explain how to properly call the studentt function and get the proper result?
Thank you!
The usage follows this documentation: http://jstat.github.io/distributions.html#jStat.studentt
So in your example you have two options. Either you can get the result immediately:
var tStat = jStat.studentt.pdf(alphaLevel, degreesOfFreedom);
Or you can return an instance that allows you to pass in multiple values of alpha:
var tStat = jStat.studentt(degreesOfFreedom);
var a1 = tStat.pdf(alpha1);
var a2 = tStat.pdf(alpha2);

Get time difference between two date strings

I want to develop a JavaScript function to calculate the activity of users based on the date in the server where the data is stored. The problem is that the date is a string like this:
2013-08-11T20:17:08.468Z
How can I compare two string like this to calculate minor and major time as in the example?
If you want to compare two dates just use this :
var dateA = '2013-08-11T20:17:08.468Z';
var parsedDateA = new Date(dateA).getTime();
var dateB = '2013-06-06T17:33:08.468Z';
var parsedDateB = new Date(dateB).getTime();
if(parsedDateA > parsedDateB) {
// do something
}
Assuming you need to do the comparisons client-side, the best way is to load the dates into Date objects using Date.parse. Then compare them using the functions provided for Date, such as getTime.
Try parse method:
var s = "2013-08-11T20:17:08.468Z";
var d = Date.parse(s);
As I have understood you in the right way, there is a good answer to your question here.
You can also look at this very good Library (DateJS).
If your problem was converting from the Date-String to js-Date look at this Page.

Categories