I am using a datatable loaded via JSON with date like this : 2010-06-03
With Opera and Chrome I have the correct date displayed as 06/03/2010. With Firefox Windows (even in safe mode, without any plug-in), I get a NaN/NaN/NaN. If I use the debug console, I see a valid date, but in Firefox Windows I can see a "Invalid date".
Bonus, with Firefox Mac awith a ton of plug-ins, we have the valid date!
Here is the setting of the date column
oColumn['editor'] =
new YAHOO.widget.DateCellEditor({asyncSubmitter:UpdateRowData});
oColumn['formatter'] = YAHOO.widget.DataTable.formatDate;
oField['parser'] = 'date';
Thanks,
Cédric
Turns out that "2010-06-03" does not return an valid Date object (at least in FF/Win). For cross-browser compatibility, be sure your value is in a format acceptable to the Date constructor:
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date
Jenny's reference is good but in case you don't want to dig, you should pass:
"YYYY,MM,DD"
into the YUI parser to get it to work in FF/Win as well as Chrome.
Depending on your situation, another way to solve this is to include an actual date constructor in your "JSON" data. Once you do so, it's no longer standard JSON and you'll need to eval it on the browser.
Eg
{'duration': 75, 'end_time': new Date(Date.UTC(2008,11,23,17,45,00,0)),
'start_time': new Date(Date.UTC(2008,11,23,16,30,00,0))}
The benefit is no longer any need to parse the data on the browser since the datum is already a date object.
The downside is that you're no longer sending valid JSON from your server to your client browsers.
Related
I'm sending LUIS a query that is based on a time value (e.g. "what is the time 10 minutes from now" - just an example). I want the time to come back in the local timezone, so on the LuisPredictionOptions object (C#) I set the TimezoneOffset (as an example I set it to 2 hours ahead, or 120 minutes).
In Fiddler I can see when it calls the LUIS endpoint it's correctly adding "timezoneOffset=120.0".
However, the timezone comes back as UTC - it doesn't matter whether the timezoneOffset is set, or even what it is set to, the time always comes back UTC, using the builtin datetimeV2 entity.
Does anyone know what the TimezoneOffset property is for? Am I just using it incorrectly? Is there another way perhaps to get a local time from LUIS?
[Update]: Here are some examples: https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/[AppId]?verbose=true&timezoneOffset=0&subscription-key=[subscriptionkey]&q=/luis/v2.0/apps/c1be57f4-3850-489e-8266-db376b82c011?timezoneOffset=120&log=true
https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/[AppId]?verbose=true&timezoneOffset=0&subscription-key=[subscriptionkey]&q=/luis/v2.0/apps/c1be57f4-3850-489e-8266-db376b82c011?timezoneOffset=240&log=true
and I'm trying the following example utterance: "in 10 minutes".
When I do this, the timex is in UTC (e.g. timex=2020-01-11T16:08:25) and the "value" comes back with the same value, minus the "T", as follows: value=2020-01-11 16:08:25
I could understand perhaps if the timex is in UTC, but then possibly "value" should be adjusted by the timezoneOffset?
It looks like there's an incorrect question mark in your URL, right before timezoneOffset.
Using the same query I was able to get the expected behavior, where the returned value is different by 10 minutes.
Which SDK are you using? Perhaps you're using the V3 Runtime SDK which uses the V3 endpoint that doesn't use timeZoneOffset but instead uses datetimeReference, and need to use the V2 Runtime SDK instead.
https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/[app-id]?verbose=true&timezoneOffset=10&subscription-key=[key]&q=in 10 minutes
The TimeZoneInfo class's FindSystemTimeZoneById method can be used to determine the correct timezoneOffset based on system time. An example in C# is shown below:
// Get CST zone id
TimeZoneInfo targetZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
// Get local machine's value of Now
DateTime utcDatetime = DateTime.UtcNow;
// Get Central Standard Time value of Now
DateTime cstDatetime = TimeZoneInfo.ConvertTimeFromUtc(utcDatetime, targetZone);
// Find timezoneOffset
int timezoneOffset = (int)((cstDatetime - utcDatetime).TotalMinutes);
Reference:
https://learn.microsoft.com/en-us/azure/cognitive-services/luis/luis-concept-data-alteration?tabs=V2#c-code-determines-correct-value-of-timezoneoffset
I am working with WKTHMTOPDF and really enjoying it. However, the page that is being converted has google maps and the resulting PDF comes out with the map half loaded. I know there was an option to add --javascript--delay in previous versions, but it would appear it is deprecated. I am using version 0.99. Is there a different option?
There is another a better way to do this that does not require using --javascript--delay (and has the advantage of not requiring you to set a delay time before you know what the required delay will actually be).
Add a callback to the 'tileloaded' event:
google.maps.event.addListenerOnce(map, 'tilesloaded', function(){
window.status = 'ready_to_print';
});
Then call wkhtmltopdf with the --window.status option set to 'ready_to_print' e.g.
wkhtmltopdf --window-status ready_to_print map.html map.pdf
obviously you can change the string 'ready_to_print' to be whatever you want so long as window.status does not already equal that value when wkhtmltopdf is called and before the above code fires.
A similar approach can be used with google charts, though the appropriate event goes by a different name.
You can use the wkhtmltopdf version 0.12.0
I am also using in websites some highly javascript contents. Previously, It was not rendering properly with version 0.99 But when I used version 0.12 with using the option --javascript-delay, everything looks fine.
You can add other options too to load your javascript perfectly i.e. --enable-javascript , --no-stop-slow-scripts etc
Be sure that you have to use proper time delay in using --javascript-delay, it depends on your site that how much time it is taking to render. If you will use more time delay then it will take more time to execute and if you will take less time delay then javascript will not be loaded properly.
The link to latest version of wkhtmltopdf
The --javascript-delay option is not deprecated at all. Also, it would be advisable to upgrade to the latest version -- 0.9.9 is a very old version.
The --javascript-delay function works, but is suboptimal for my usage -- maybe your usage is variable as well? The PDF can sometimes contain a list of just a dozen items and their map view, or hundreds of items on the map. There is no one right msec delay for me...
I successfully used #rohit-singhal tip (Rails app using GMaps4Rails gem and haml views) inside the controller method:
def index
...
respond_to do |format|
format.pdf do
#map_data = { markers: #map_hash, zoom: 10, cluster_zoom: 10, center: center_coordinates,
fit_to_bounds: true, show_center_marker: false, map_type: 'roadmap'}
render pdf: 'Water Supplies',
disposition: 'inline',
layout: 'layouts/pdf.html.haml',
show_as_html: params.key?('debug'),
no_stop_slow_scripts: ''
end
end
end
And I used #mwag's tilesloaded callback as well. (Verbatim in the google maps generation javascript.) The controller line of interest to switch out the no_stop_slow_scripts for:
...
window_status: 'ready_to_print'
...
Both worked. Not sure if there are any advantages to one or the other.
I'm trying to post data (a chunk of a file) using a XmlHttpRequest object with an Int8Array as the data but it fails in FF18, but works perfect in IE 10 & Chrome.
Here's my JS:
//dataObj is an Int8Array with approx. 33,000 items
var oReq = new XMLHttpRequest();
oReq.open("POST", "Ajax/PostChunk");
oReq.onload = function (oEvent) {
//
};
oReq.send(dataObj);
I use Firebug in Firefox to debug my JS and when I watch the activity under the Net tab, nothing ever shows up for this XHR call. As if it was never called.
Also, prior to this call, I call jQuerys .ajax() method for "Ajax/PostChunkSize" and that works fine in all browsers, although that doesn't use an Int8Array for its data. I can't use .ajax() for this since .ajax() doesn't support Int8Array objects, as far as I know.
Does anyone know why Firefox doesn't even attempt to send this? Any questions, please ask.
Thanks in advance.
The ability to send a typed array (as opposed to an arraybuffer) is a recent addition to the in-flux XMLHttpRequest2 spec. It'll be supported in Firefox 20 in April or so (see https://bugzilla.mozilla.org/show_bug.cgi?id=819741 ) but in the meantime if your Int8Array covers its entire buffer, doing send(dataObj.buffer) should work...
Note that per the old spec the code above should have sent a string that looks something like "[object Int8Array]" instead of throwing; you may want to check to make sure that other browsers really are sending the array data and not that string.
i am using datepicker to insert date on my form, which of course returns date to the controller as a string.
the issue is when I try to convert this string to date, I get an error "invalid date"
Date.parse(params[:abc][:date])
To verify if I'm doing it right, I wrote the following ruby program:
string_date = "06/18/2011"
date = Date.parse(string_date)
puts date
This works perfectly fine. But when I try the same thing in my rails controller, it gives invalid date error.
please help.
When I do this in my Rails 3.1 console:
date = Date.parse("06/18/2011")
I get an "ArgumentError: invalid date" exception. However, it works fine with an ISO-8601 date:
date = Date.parse('2011-06-18')
So perhaps you're having a locale problem. Your script could be using your standard locale setting (which is probably some US locale judging by the date format) but your server is probably using something else.
Try changing the jQuery datepicker date format to something standard and unambiguous by adding this:
dateFormat: 'yy-mm-dd'
to the datepicker's options. The datepicker's default is 'mm/dd/yy' and Ruby's Date class doesn't like seem to like it without a special locale setting.
I am trying to incorporate this script here (http://snippets.dzone.com/posts/show/7530), yet i'm no ruby wizard.
Right now it pulls down mail that I want with the local_file name, but was wondering if its possible to have it pull it down and save it by the 'message subject title + date of message'. When I try using mail.date, I get a longer than normal string, and can't convert it with Time.parse().
For instance, right now it pulls down an attachment as 103134.htm, which has no significance to me, and I'd rather have it be "Logs from Blah - 11/12/2009.htm" since it pulls the subject and date from the original message instead of the attachment local_name.
Any help would be greatly appreciated!
Thanks!
mail.date already returns a Time object, so it is not required that you parse it again. Instead use mail.date.strftime("%m/%d/%Y") to get your desired output