Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Zimlets

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-08-2007, 04:25 PM
Loyal Member
 
Posts: 97
Default ZmMsg date and time

Working on a Zimlet, needed to get email message time inside of a doDrop

There is got to be a better way but this worked. Took me 3 hours to hunt this down!
Code:
var formatter = AjxDateFormat.getDateTimeInstance(AjxDateFormat.FULL);
var xdate =  formatter.format(new Date(obj.date)) ;
__________________
EricX

Last edited by Ericx; 02-11-2007 at 09:40 AM..
Reply With Quote
  #2 (permalink)  
Old 02-11-2007, 09:23 AM
Loyal Member
 
Posts: 97
Default Custom Date Time!

I'm sure for the experienced java guys custom date and time is pretty easy. But for PHP users... this write up should save you a bunch of time.

Zimbra uses a custom date formatting class AjxDateFormat. It's similar to the well documented Java Simpledateformat class, but I can't get to that class very easy from within a zimlet. There are probably some other benefits from using the Zimbra custom AjxDateFormat class. If you want to see some of the options and usage for that class you con look at the file, as well as the source class. ( I have not posted where the source class is, short on time, but do a search through the source code and you can find it.)

/opt/zimbra/tomcat/webapps/zimbra/js/AjaxNewWindow_all.js


In the above mentioned file you can search for AjxDateFormat to see many of the options. There are some already built options like
.short, .medium, .long, .full as well as some to get the month name and such. I'm using the date meta options to create the date exactly as I want it. This is more what I'm used to doing in PHP and should be familiar to php users.

------
My java object is obj.date. This outputs as a string or int, not really sure what it is, but not a date object. We have to stuff obj.date into a new date object so we can format it.
Code:
//obj.date is the time of our email message from doDrop.
var formatter =new AjxDateFormat("yyyy-mm-dd HH:mm:ss");// example output 2007-01-09 17:30:20
var Xdate = formatter.format(new Date(obj.date)) ;
Now I can pass Xdate to my custom form and it's formatted the way I like it.

----
If you want something that the user can read more easily. Create two inputs in your form
1. readonly using .long which should look something like Friday, Jan 9 1971 (this is from memory so don't quote me on it).
2. a hidden input field with the value = to the date you want to pass into your other database. Something like mike which looks like 2007-01-09 17:30:22.
__________________
EricX

Last edited by Ericx; 02-11-2007 at 09:39 AM..
Reply With Quote
  #3 (permalink)  
Old 02-12-2007, 12:36 PM
Zimlet Guru & Moderator
 
Posts: 467
Default

Quote:
Originally Posted by Ericx View Post
I'm sure for the experienced java guys custom date and time is pretty easy. But for PHP users... this write up should save you a bunch of time.

Zimbra uses a custom date formatting class AjxDateFormat. It's similar to the well documented Java Simpledateformat class, but I can't get to that class very easy from within a zimlet. There are probably some other benefits from using the Zimbra custom AjxDateFormat class. If you want to see some of the options and usage for that class you con look at the file, as well as the source class. ( I have not posted where the source class is, short on time, but do a search through the source code and you can find it.)

/opt/zimbra/tomcat/webapps/zimbra/js/AjaxNewWindow_all.js


In the above mentioned file you can search for AjxDateFormat to see many of the options. There are some already built options like
.short, .medium, .long, .full as well as some to get the month name and such. I'm using the date meta options to create the date exactly as I want it. This is more what I'm used to doing in PHP and should be familiar to php users.

------
My java object is obj.date. This outputs as a string or int, not really sure what it is, but not a date object. We have to stuff obj.date into a new date object so we can format it.
Code:
//obj.date is the time of our email message from doDrop.
var formatter =new AjxDateFormat("yyyy-mm-dd HH:mm:ss");// example output 2007-01-09 17:30:20
var Xdate = formatter.format(new Date(obj.date)) ;
Now I can pass Xdate to my custom form and it's formatted the way I like it.

----
If you want something that the user can read more easily. Create two inputs in your form
1. readonly using .long which should look something like Friday, Jan 9 1971 (this is from memory so don't quote me on it).
2. a hidden input field with the value = to the date you want to pass into your other database. Something like mike which looks like 2007-01-09 17:30:22.

This is great info, can you put it up on the wiki?
Reply With Quote
  #4 (permalink)  
Old 02-12-2007, 01:04 PM
Loyal Member
 
Posts: 97
Default Update

My previous code did not work so well. It looked like it worked but the month was giving me the minutes. This is how I got around it.
Code:
	
var formatter_date =new AjxDateFormat("yyyy-MM-dd");
var formater_time = new AjxDateFormat("HH:mm:SS");
var pretty_date = formatter_date.format(new Date(obj.date));
var pretty_time = formater_time.format(new Date(obj.date));
this.email_dtime = pretty_date + " " + pretty_time;
I'll try to post it on the wiki soon.
__________________
EricX
Reply With Quote
  #5 (permalink)  
Old 02-12-2007, 07:51 PM
Zimlet Guru & Moderator
 
Posts: 467
Default

Quote:
Originally Posted by Ericx View Post
My previous code did not work so well. It looked like it worked but the month was giving me the minutes. This is how I got around it.
Code:
	
var formatter_date =new AjxDateFormat("yyyy-MM-dd");
var formater_time = new AjxDateFormat("HH:mm:SS");
var pretty_date = formatter_date.format(new Date(obj.date));
var pretty_time = formater_time.format(new Date(obj.date));
this.email_dtime = pretty_date + " " + pretty_time;
I'll try to post it on the wiki soon.
Makes sense, that's pretty close to the pattern that you see in Java. The only thing negative I will ever say about Zimbra is that the DWT code (quite deliberately I believe) very much is modeled directly on SWT/Swing/Java patterns. I think that's part of the reason that DWT "feels" much heavier then YUI, Prototype/etc (all things that I have been playing with recently).
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.