CalendarXP.net Support Forum Index CalendarXP.net Support
Most forums here are private and invisible to public.
 
 FAQFAQ   SearchSearch   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to customize a date format to be like "Monday, August 18, 2003"?

 
Post new topic   Reply to topic    CalendarXP.net Support Forum Index -> CalendarXP F.A.Q.
View previous topic :: View next topic  
Author Message
calendarxp
Site Admin


Joined: 30 Jan 2005
Posts: 409

PostPosted: Tue Feb 15, 2005 6:48 pm    Post subject: How to customize a date format to be like "Monday, August 18, 2003"? Reply with quote

Although most common date formats can be easily set via the theme options, sometimes user do need special customized ones. It's not difficult as long as you know how to intercept the input and output of the calendar.

Now let's illustrate the process of setting a format of "WEEKDAY, MMM DD, YYYY", which is not directly supported by the theme.

1st, set the date format in the theme-name.js (e.g. normal.js) file to be "YYYY-MMM-DD", as following
Code:
var gsSplit="-"; // separator of date string, AT LEAST one char.
var giDatePos=2; // date format sequence 0: D-M-Y ; 1: M-D-Y; 2: Y-M-D
var gbPadZero=false; // whether to pad the digits with 0 in the left when less than 10.
var giMonthMode=1; // month format 0: digits ; 1: full name from gMonths; >2: abbreviated name
var gbShortYear=false; // year format true: 2-digits; false: 4-digits

2nd, add the following to your plugins.js:
Code:
function fParseInput(str) {
  var dt=/^(\w+), (\w+) (\d{1,2}), (\d{4})$/.exec(str);
  if (dt==null) return null;
  else return fParseDate(dt[4]+gsSplit+dt[2]+gsSplit+dt[3]);
}

function fFormatInput(y,m,d) {
  var str=fFormatDate(y,m,d).split(gsSplit);
  var d=new Date(y,m-1,d).getDay();
  var wd=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
  return wd[d]+", "+str[1]+" "+str[2]+", "+str[0];
}

Note: We used the regular expression in the fParseInput to simplify the parsing code. You may need to change it whenever you need a different format.

_________________
Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    CalendarXP.net Support Forum Index -> CalendarXP F.A.Q. All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Copyright 2003- Idemfactor Solutions, Inc. All rights reserved.
Powered by phpBB © 2001, 2005 phpBB Group