Flex - Date serialization - apache-flex

Does anyone know how to get actionscript to render a null date value '000:00:00T00:00:00'? I am calling a web service that expects date fields in the SOAP xml. I need some of these dates to serialize as null and I can't see how to produce null. The closest value I can get is '1899-11-30T00:00:00Z'. Below is the code I am using:
var dateStr:String = "0000-00-00T00:00:00+";
var emptyDate:Date = DateUtil.parseW3CDTF(dateStr);
newReqData.DateTimeInit = emptyDate;

You can probably do it with a date formatter. You'll have to create a Date object but if you pass it to the DateFormatter, you can set the format to pretty much whatever you like. Here's the reference and I would recommend looking at the "Other Text" area:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/formatters/DateFormatter.html

var d:Date=new Date();
d.setTime(-62167226400000);
Alert.show(d.toString());
or as said Shawn Yale, read this.

Related

How to force RFC3339 string for all datetime for queries upon display as API?

Using Cake 3.2.4
What am I getting now?
Whenever a query is executed and there is a datetime field, it will be displayed as RFC2822 string.
e.g. "2016-07-18T09:00:00+0800"
What do I want?
I want RFC 3339 string
e.g. "2016-07-18T09:00:00+08:00"
What did I try?
$paginationQuery->formatResults(function (\Cake\Datasource\ResultSetInterface $results) {
return $results->map(function ($row) {
$datetime = $row['start_date'];
$row['start_date'] = $datetime->format(\DateTime::RFC3339);
return $row;
});
});
I kinda forced the original datetime object to display as string.
Okay, so what's wrong?
I am unsure if it's wrong to do so. As you can see clearly, the original value for $row['start_date'] is actually a datetime object. Not a string.
Can I keep the value as datetime object but when it gets displayed as api, it uses the RFC3339 format?

SDL Tridion GetListKeywords using Anquilla Framework

I'm writing a GUI extension and using the Anquilla framework to get a list of Keywords within a Category. I'm obtaining an XML document for the list of keywords then working with that document within my extension.
My problem is that the returned XML doesn't contain the Keyword's 'Description' value. I have the Title and Key etc.
My original code looks like this:
var category = $models.getItem("CATEGORYTCMID:);
var list = category.getListKeywords();
list.getXml();
A typical node returned is this:
<tcm:Item ID="tcm:4-1749-1024"
Type="1024" Title="rate_one" Lock="0" IsRoot="true"
Modified="2012-12-17T23:01:59" FromPub="010 Schema"
Key="rate_one_value" IsAbstract="false"
CategoryTitle="TagSelector"
CategoryID="tcm:4-469-512" Icon="T1024L0P0"
Allow="268560384" Deny="96" IsNew="false"
Managed="1024"/></tcm:ListKeywords>
So I've tried using a Filter to give me additional column information:
var filter = new Tridion.ContentManager.ListFilter();
filter.columns = Tridion.Constants.ColumnFilter.EXTENDED;
var list = category.getListKeywords(filter);
Unfortunately this only gives the additional XML attributes:
IsShared="true" IsLocalized="false"
I'd really like the description value to be part of this XML without having to create a Keyword object from the XML. Is such a thing possible?
cough any ideas? cough
I'm afraid you'll have to load the Keyword itself to get the Description.
It's not used in any lists, so it's not returned in the XML.
You could always create a List Extender to add this information to the list, but try to be smart about it since this extender will execute everytime a GetList is called.
Won't save you from having to open every keyword in the list, but you'll be doing it server-side (with Core Service/NetTcp for instance) which will probably be easier and faster than opening each keyword with Anguilla.
In this instance I only need the one keyword, so I simply get it from the CMS. Getting an object in Anguilla is a bit weird, here's the code:
In your main code area:
var selectedKy = $models.getItem("TcmUriOfKeywordHere");
if (selectedKy.isLoaded()) {
p.selectedKy = selectedKy;
this.onselectedKyLoaded();
} else {
$evt.addEventHandler(selectedKy, "load", this.onselectedKyLoaded);
selectedKy.load();
}
It's worth noting how I store the keyword in the properties of the item, so I can obtain it in the onselectedKyLoaded function
The function called once the item is loaded
ContentBloom.ExampleGuiExtension.prototype.onselectedKyLoaded = function (event) {
var p = this.properties;
var selectedDescription = p.selectedKy.getDescription();
// do what you need to do with the description :)
};
I resolved this, thanks to the answer here: https://stackoverflow.com/a/12805939/1221032 - Cheers Nuno :)

showing DateTime in simple format?

i have a column in my database that stores DateTime, now i want to show time in simple format,
you know it will appear like : 12/26/2011 9:39:55 PM
but i want to show it in persian.
When you want to format the DateTime in your application, you need to use a DateTime.ToString overload.
Select the appropriate standard Date and Time format string - in this case "g" looks like a good fit.
If you have not set up your webserver to use the fa-IR culture by default, you will need to pass this culture in as well.
string farsiDate = myDateTime.ToString("g", CultureInfo.GetCultureInfo("fa-IR");
Have a look at the examples on MSDN for using the PersianCalendar class.
var cal = new PersianCalendar();
var today = DateTime.Now;
var persianDate = string.Format("{0}/{1}/{2}",
cal.GetDayOfMonth(today),
cal.GetMonth(today),
cal.GetYear(today));

ExtJs 4 Displaying WCF DateTime

I can't figure out how convert the datetime that wcf outputs into a datetime that ExtJs can use. I have found lots of articles about this but they are all for ExtJs 3 and I couldn't get it to work with 4.
I did find this code but I don't know how I could use it to convert everything in my JsonStore.
//this method is used to convert the MS JSON date format to the ExtJS Grid Date Column Value
function dateFormatter(dt) {
/// <summary>this method is used to convert the MS JSON date format to the ExtJS Grid Date Column Value</summary>
/// <param name="dt">Actual JSON Date Value</param>
try {
//microsoft JSON date format needs to convert into Javascript date
var newdata = dt.replace(/\/Date\((-?[0-9]+)([+-][0-9]+)?\)\//g, "new Date($1)");
newdata = eval('(' + newdata + ')');
return newdata.format('m/d/Y');
}
catch (e) {
return dt;
}
}
Unlike Ext JS 3, Ext JS 4 does not extend the native Date object. Instead it provides Ext.Date. So instead of:
date.format('m/d/Y');
you would instead use:
Ext.Date.format(date, 'm/d/Y');
Additionally using eval() is a really bad idea most of the time. This code is no exception.
And if you drop eval, the try-catch is also not needed.
Finally, a function that both parses a date and converts it to another format seems to be doing too much. Often you will want to display the same date in different formats in different parts of your app. Therefore I would rather just have a function that parses the WCF date format into JavaScript Data object. And then use convert the Date object into particular string format at the very place where it's needed.
Removing all extraneous stuff, this is what I get:
function parseWcfDate(dt) {
var milliseconds = dt.replace(/\/Date\((-?[0-9]+)([+-][0-9]+)?\)\//, "$1");
return new Date(parseInt(milliseconds, 10));
}
Anyway, all this is too much trouble... Ext JS has built-in support for parsing WCF formatted dates:
Ext.Date.parse("/Date(1234567894560)/", "MS");
Also see:
How to handle json DateTime returned from WCF Data Services (OData)
How do I format a Microsoft JSON date?
Use JSON.NET with JavaScriptDateConverter.

How to pass a Date object from Flex to a JSP Servlet?

I am passing some parameters as POST to a Servlet from my Flex WebApplication. I am able to pass and retrieve strings properly.
I used new Date().getTime() in my flex code and tried passing the timestamp variable hoping to parse it at the servlet and convertit into a java.util.Date object. But i am getting a NumberFormatException when i try to parse the variable from the string that i got from request.getParameter.
Any solutions?
I think you are not converting String to long in Java IF so Please try
String strDateinmilliseconds = request.getAttribute("FlexMilliseconds");
long dateinmilliseconds = Long.valueOf(strDateinmilliseconds);
Date resultdate = new Date(dateinmilliseconds);
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
System.out.println(sdf.format(resultdate));
Hopes that helps

Resources