Forecast.io using Time argument with JSONP not working - jsonp

My plan is to display the past 3 days of various weather stats to the user but I am unable to use the time argument properly. Here is my code:
var forecastURL = "https://api.forecast.io/forecast/API_KEY/".concat(lat,lng,new Date().toISOString().replace("Z","-72:00"));
$.ajax({
url: forecastURL,
jsonp: "callback",
dataType: "jsonp",
success: function(response) {
console.log(response);
}
});
I'm not sure I'm doing the date right but all I'm getting is a warning saying getDefaultPrevent is deprecated. Is something else at fault or is it just my date? If it's the date, what's the proper structure for manipulating ISO 8601 strings to look in the past? Preferrably 7 days if possible.

Firstly, in this use concat does not return commas between the values, so my code below uses the + "," + method rather than create another variable which is what you would need to do if you wanted to use concat.
Secondly, in ISO timestamps, ie:
2015-05-25T20:56:15.179Z
The Z means the UTC offset of the time is zero. This can be replaced by something like +1000 for times in UTC + 10 hours. If you wish to change the time value itself then the UTC offset is not the place to do it.
var d = new Date();
d.setHours(d.getHours()-72);
var forecastURL = "https://api.forecast.io/forecast/API_KEY/" + lat + "," + lng + "," + d.toISOString();
//Your existing AJAX call would go here
You could replace getHours and setHours with getDate and setDate or any of the other JS date functions.
I can't test the JSON part of your question as I don't have an API key but it looks like it should work. Find some more info about JSON in jQuery here.

Related

How to format date for BigCommerce blog post

I keep getting errors while trying to create blog posts via API calls to BigCommerce, due to the published_date_iso8601 field.
This field expects the date string in this kind of format "5/18/2018 1:26:42 PM", as per the docs here: https://developer.bigcommerce.com/api-reference/1b41aac9b9f54-create-a-blog-post
My data has the dates in this format: "2022-05-12T13:09:23-07:00"
I am using Javascript, and I have tried multiple ways to transform the format, but no success so far.
I have tried built-in JS Date methods
const originalDate = "2022-05-12T13:09:23-07:00"
const newDate = new Date(originalDate).toISOString()
I have tried using Moment
const originalDate = "2022-05-12T13:09:23-07:00"
const newDate = moment(
originalDate
).format('DD/MM/YYYY HH:mm:ss A')
And multiple variations of formatting besides those 2 examples, but I still can't get the post to go through. The error is only a 400 code with no message.
Anyone know how to format this?
Try using the published_date field and new Date('2022-05-12T13:09:23-07:00').toUTCString()?
Hopefully, this should work for you.
A

How to format Date received from Element-UI

I'm making use of the datepicker from Element Ui where the user can select a range in dates. When the user fills in the datepicker, this is what I get back: ['2018-01', '2019-02'] . So just an array with two String elements. NOT a Date() object.
When dynamically outputting this to the user, I would like to show it as: January 2018 - February 2019
I got it somewhat working in my project but the code just really sucks and also doesn't work properly either. Checkout this gif of my current project and somewhat desired result. I was wondering if someone knows a good and easy way of achieving my desired result without too much hassle. I cannot use methods like toLocaleDateString() because it isn't a Date() object. I've got my code working in a Codesandbox. If any if you guys knows a solution feel free to edit the listed Codesandbox, I would highly highly appreciate it!
In the Codesandbox I got a computed property formateDate. The basic idea of the computed property is to cut the elements of the array I get back from the datepicker before and after the - effectively giving me the first & second month and first & second year. That data I store in these variables:
let monthOne;
let monthTwo;
let yearOne;
let yearTwo;
Since I get the months back as '01' and '02' for example, I created an array of objects to transform the '01' and '02' to January and February with a for loop. I then store the result in a new variable with:
displayDate = monthOne + ' ' + yearOne + ' - ' + monthTwo + ' ' + yearTwo;
Lastly, I tried to store that result into the timeperiodDisplayString at the correct index in the experience array of objects. Anyway, I'm probably overcomplicating this way to hard so I would REALLY appreciate any help with this.
Maybe you could map over the result from the datepicker component to create an array of Date objects. So you can use toLocaleDateString()
Something like this should work:
['2018-01', '2019-02'].map((date) => {
const split = date.split('-');
return new Date(split[0], +split[1] - 1);
});
You can use parse() function from javascript.
var d = Date.parse("2019-01");
console.log(new Date(d));

Date object "forgets" formatter?

Is there an error in the handling of formatter objects when using Perl6's Date? If I manipulate the dates after instantiating the object, it seems as if the formatter returns to the default.
my $d = Date.new(2019, 12, 25, formatter => { sprintf "%02d/%02d in %04d", .month, .day, .year });
# Outputs 12/25 in 2019
$d.later(:1day)
# Outputs 2019-12-26
I expected the output after invoking the .later method to be "12/26 in 2019".
When looking at Date.pm6 over on GitHub -- https://github.com/rakudo/rakudo/blob/master/src/core/Date.pm6 -- I see that the .later method creates new Date objects using .new without referencing to the formatter that's set. I.e. should line 151
self.new-from-daycount(self.daycount + $multiplier * $amount )
rather be something like
self.new-from-daycount(self.daycount + $multiplier * $amount, &!formatter )
?
If so this is missing in lots of places, not only in .later, but .succ, .pred etc.
Looks like this was an oversight in the dispatch to new-from-daycount, which got fixed with: https://github.com/rakudo/rakudo/commit/ac11774d73 .
I think this should fix all issues. Please do make an issue at https://github.com/rakudo/rakudo/issues/new if not.
#elizabeth - this fixed the issue when adding days, but not other intervals. I guess the same fix has to be done on multiple locations.
This fixed the problem for iterating days, but not for months, years, etc.
> my $d = Date.new(2019,12,24, formatter => { sprintf "%04d/%02d", .year, .month };
2019/12
> $d.later(:1day);
2019/12
...but...
> $d.later(:1month);
2020-01-24

Pentaho kettle convert date to unix

I'm trying to pacha a string format dated "2019-05-14 13:30:00" to a UNIX format.
In javascript I got it but in the javascript kettle module I am not able to return the numeric value 1557833442
the line of code is this:
const tests = (new Date ("2019-05-14 13:30:00"). getTime () / 1000);
It looks like the Date() constructor doesn't like the format you are using.
If you want the current date, use a Get System Info, it has a number of useful date options.
If you are converting an incoming field, use the Select Values step to change the metadata, using the format string that matches your string field's format.

fnReloadAjax(url): two requests

I'd like to refresh my table when new item is added. I use such code:
$("#frm_create_user").submit(function() {
var formData = getFormData($("#frm_create_user"));
$.ajax({
type: "POST",
url: getApiUrl("/user"),
dataType: "json",
contentType: 'application/json',
data: JSON.stringify({user:{user_ref: formData.user_ref}}),
}).done(function(r) {
oTable.fnReloadAjax(getApiUrl("/users?sSearch=" + r.user.userid));
});
return false;
});
But for some reason, I can see two requests instead of one.
The first one is correct - http://symfony/app_dev.php/api/users?sSearch=kZoh1s23&_=1394204041433
And the second one is confusing - http://symfony/app_dev.php/api/users?sSearch=kZoh1s23&sEcho=3&iColumns=8&sColumns=&iDisplayStart=0&iDisplayLength=25&mDataProp_0=userid&mDataProp_1=user_ref&mDataProp_2=password&mDataProp_3=vpn_password&mDataProp_4=status_id&mDataProp_5=expire_account&mDataProp_6=created&mDataProp_7=&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&sSearch_1=&bRegex_1=false&bSearchable_1=true&sSearch_2=&bRegex_2=false&bSearchable_2=true&sSearch_3=&bRegex_3=false&bSearchable_3=true&sSearch_4=&bRegex_4=false&bSearchable_4=true&sSearch_5=&bRegex_5=false&bSearchable_5=true&sSearch_6=&bRegex_6=false&bSearchable_6=true&sSearch_7=&bRegex_7=false&bSearchable_7=true&iSortCol_0=0&sSortDir_0=asc&iSortingCols=1&bSortable_0=true&bSortable_1=false&bSortable_2=true&bSortable_3=true&bSortable_4=true&bSortable_5=true&bSortable_6=true&bSortable_7=true&_=1394204041505
If I remove fnReloadAjax() line, these two requests gone so that it looks like it is caused by fnReloadAjax()
How may I fix it to have only http://symfony/app_dev.php/api/users?sSearch=kZoh1s23&_=1394204041433 requests?
All these confusing parameters are Informations that your server sided script might need to clamp the data that has to be returned to dataTables.
Since I don't know your server sided code, I can only break up what they are good for:
&sEcho=3 //No need to react to this, it's just the result of the last ajax call
&iColumns=8 //Your table has 8 columns
&iDisplayStart=0 //You are on page 1
&iDisplayLength=25 //you want to display up to 25 entrys per page
&mDataProp_0=userid //Your first colum gets the value of [userid]
&mDataProp_1=user_ref //Your first colum gets the value of [user_ref]
&mDataProp_2=password //Your first colum gets the value of [password]
etc...
&sSearch=12345&bRegex=true//Your first column is filtered by userid 12345 and this value should be treated as a regex by your datasource
&sSearch_0=&bRegex_0=false//Your second column is not filtered and should not be treated as a regex by your datasource
etc...
&iSortCol_0=0&sSortDir_0=asc //your first column should be sorted ascending
&iSortingCols=1 //you have one column that is sortable
&bSortable_0=true //Column 0 is sortable
&bSortable_1=false //Column 1 is not sortable
etc..
Your server sided script should react to these values. In case of a mysql datasource it should set up its where clause to the filtering parameters, limit it by pagenumber and items per page, and sort according to the sortinfo.
All this is needed if you want to use the luxury features of datatables like pagination, sorting, individual column filtering, clamping ajax return values to minify serverload when working with thousands of entrys.
If you don't need that, just ignore the additional parameters in your server script and just react to the data you need. But leave them in, you might need them later:-)
Hope this helps