FireBreath: how can I pass dates from my plugin to Java Script - date

I'm trying to create a simple FireBreath plugin. I need to pass a date from JavaScript to my plugin and to get date from my plugin and use it in JavaScript.
I have an idea about getting date in FB plugin from JS. I can use a FB::JSObjectPtr parameter and get it's attributes with GetAttribute.
The main question is how to pass a date back to JS? The only way I can find in my head is to create class DateJSAPI derived from FB::JSAPIAuto an implement all methods so JS can use instance of my class as JS Date.
I don't like such a weird way.
Can anyone advise me some good way of returning date to JS?

I spent several hours once trying to find a way to create Date objects in a NPAPI plugin (specifically in FireBreath) and it seems the only way to do so is to create a javascript function that returns a date object. Given that you'd have to pass a string or timestamp into said function it seems silly to do this.
If I were you I'd just send it as a timestamp (number) so you can convert it to a Date object once it gets to javascript.

Related

class Zend_Date not found

I googled a lot until now, but I couldn't find anything that works.
I need to save a proper datetime value in my mySQL database, so I tried as used in ZF1 this one:
$date = new Zend_Date();
echo $date->toString('YYYY-MM-dd HH:mm:ss');
I got the error class Zend_Date not found
Blockquote
What is it in ZF3, is it deprecated? If yes how is the name of the new class and how to get with composer. If not, what is wrong, what do I need as use statement.
Of course this one works
$heute = date("Y-m-d H:i:s");
But the question is furtherhin why can't I use Zend_Date?
When PHP 5.3 released, it has DateTime built in class. That's why Zend_Date was not used anymore. So, since ZF2 Zend_Date was not exist anymore.
So, just use DateTime built in class, and this doesn't need loaded in composer.
http://php.net/manual/en/class.datetime.php
Under this link you have all zf3 components:
https://docs.zendframework.com/
It looks like there is no longer Zend_Date in zend framework components.
P.s.
I recommend using Carbon (http://carbon.nesbot.com) or built-in php date functions. I prefer object-oriented style:
http://php.net/manual/en/class.datetime.php

what is the best way to specify default value for a date parameter in ireport

I have created a parameter in iReport Value_DT with Date data type.
If I'm using expression "new java.util.Date("01-SEP-14") as default value it works fine but this is hard code.
I'd like to use user defined function from Oracle DB, i.e. it might be similar to "new java.util.Date(new java.util.Date($F{GETACCOUNTINGDATE})) where GETACCOUNTINGDATE is oracle function.
With such syntax I have an error "The constructor Date(Timestamp) is undefined".
What should be changed in order to use function from DB in default parameter?
I'm not sure of any way to do this directly in the default value expression without writing custom code. I believe you would need to write a custom class with a static method which connects to your database, calls GETACCOUNTINGDATE, and returns the date. You could then, bundle this as a JAR, put it in your classpath and call this method in your Default Value Expression.
That's quite a bit of work though, so alternatively you may be able to 'recreate' the date using Java Date Function libraries.
We've used apache dateUtils:
org.apache.commons.lang.time.DateUtils.addMonths(new Date(),0))
I know a colleague has used jchronic to use strings and create dates.

Do I need to provide an IFormatProvider when converting a date to a string with a specific format?

If I'm using this:
DateTime.Now.Date.ToString("yyyy-MM-dd")
FXCop complains that I'm violating CA1305 and says that I should provider an IFormatProvider. Do I need to? I'm asking for the date in a specific format anyway (which is the format I'm expected to put it into the XML as).
Would providing a format provider make any difference? Might it actually produce the wrong results in this case?
Why don't you want to specify the format provider?
If it is just laziness then I can recommend defining two snippets. ic for CultureInfo.InvariantCulture and cc for CultureInfo.CurrentCulture.
Never assume anything about how conversion to string works with the default culture. Not everyone in the world uses the gregorian calendar. Some day you customer might hire a contractor with a computer with another calendar as default and then you are not generating correct XML. Explain then to your customer that you didn't want to follow the FxCop recommendation.
Best thing would be if .Net included a Xml Culture. Then you could just do
DateTime.Today.ToString("d", CultureInfo.Xml)
For some reason Microsoft choose to create a separate class instead XmlConvert. The class has been there since .Net 1.0.
XmlConvert.ToString(DateTime.Today, "yyyy-MM-dd")
will always create a correct Xml date.
Not sure if it is bug or intended behaviour but XmlConvert.ToString(DateTime.Today, "d") will not create a valid Xml date.
so after a bit more research it seems that in my instance it doesn't make any difference, but in the general case months might be displayed in a specific locale.
More details here:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

Jasper Reports Custom global or built in parameter

In my application I have a setting that can be configured by the user called Date Format. There are a list of formats they can use and when they choose one, all dates in the application and in the reports use that format.
Every time I create a new report I have to create the parameter and link the input control. I just added a new setting, for formatting numbers. I have about 50 reports that I need to apply this to. After going through the monotonous task of adding the parameter and input control to every report I was wondering if there is an easier way.
Is it possible to create a custom global parameter that is automatically available to all reports (Similar to the built in parameters)?
Furthermore, is there a way to tell jasper if a field is of a certain type to automatically do something with it, on a global level. For example if my field type is 'decimal' apply the number format?
Every report has a REPORT_FORMAT_FACTORY parameter that is an instance of net.sf.jasperreports.engine.util.FormatFactory. You should be able to create your class that implements FormatFactory and in the constructor takes what ever you need to determine the correct format. Then add it to the parameters when exporting your report.
You will probably need to play with it, as I am not sure what it passes in for pattern when a value is/isn't set. And if you always ignore the pattern, then when you need to explicitly set it to be the same in all reports it will cause problems.
If I get time tonight, I will try to create an example and see how it works and update my answer, or if you beat me to it, you could post a comment letting us know how it works.

chrome detecting integer as NPVariantType_Double with npruntime plugin?

I am trying to call a function through javascript via my NPRuntime plugin
but when i pass an integer value to a function,chrome detects that as NPVariantType_Double while firefox is taking same as NPVariantType_Int32.
Can we do avoid this without modifying script to make sure that both firefox and chrome detects it as NPVariantType_Int32.
Short answer: no, not really. They will give it to you in the format that they decide to give it to you. I recommend you cast it to a int32.
If you're really worried about how it's going to come in and need the format to remain exactly the same, pass it as a string and use some form of lexical cast to convert it to the numeric format you need.
Remember that javascript is dynamically typed, so from their perspective it shouldn't matter. This is just one of those annoying things :-/ FireBreath "solves" this issue simply by not caring what the browser provides and converting it to the datatype the function says it expects.
Taxilian is right. Chrome and Opera(as far as I recall) are returning mainly NPVariantType_Double , even if this represents the location of an element (in pixels).You can create a function that converts NPVariantType_Double and NPVariantType_Int32 to whatever you want.