JosephMajaseSithole / datejs

Automatically exported from code.google.com/p/datejs
0 stars 0 forks source link

[FIXED] Date().toString() support for PHP's strftime #34

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Could there please be added support for PHP's strftime syntax.
http://php.net/strftime

Original issue reported on code.google.com by balup...@gmail.com on 20 Mar 2008 at 12:30

GoogleCodeExporter commented 8 years ago
Also the date function syntax:
http://au.php.net/manual/en/function.date.php

I think it is really important to get a universal thing going on.

Original comment by balup...@gmail.com on 20 Mar 2008 at 12:38

GoogleCodeExporter commented 8 years ago
I've come up with the following as a temporary solution.

Original comment by balup...@gmail.com on 20 Mar 2008 at 1:29

Attachments:

GoogleCodeExporter commented 8 years ago
@balupton - ok, A while back I also played with this same concept of just 
converting
the PHP/Unix date format into a Java/.NET date format. Your persistence got me
thinking again and I've reconsidered adding the functionality into the library. 
The
conversion function probably will not make it into the core library, but I will 
add
to an optional "extras.js" module.

Original comment by geoff%co...@gtempaccount.com on 26 Mar 2008 at 5:42

GoogleCodeExporter commented 8 years ago
Ok awesome, problem is that the PHP date/strftime also have a lot more things 
than
Date.toString, so will you be working on adding that, or just make a conversion 
function?

And thanks a bunch!

Original comment by balup...@gmail.com on 27 Mar 2008 at 1:58

GoogleCodeExporter commented 8 years ago
@balupton - I added a new extras.js module that includes a the .format() 
function
which takes a Unix/PHP date format string as a parameter. 

The .format() function supports all the format specifiers. Each format 
specifier is
listed in the FormatSpecifiers wiki documentation. See
http://code.google.com/p/datejs/wiki/FormatSpecifiers

I also added a Date.normalizeFormat() function which will converts a PHP format
string to Java/.NET format string. A PHP format string can be used with 
.$format or
.format. A Java/.NET format string can be used with .toString(). The .parseExact
function will only accept a Java/.NET format string 

Example

Date.normalizeFormat("%m/%d/%y"); // "MM/dd/yy"

var f1 = "%m/%d/%y"
var f2 = Date.normalizeFormat(f1); // "MM/dd/yy"

new Date().format(f1);    // "04/13/08"
new Date().$format(f1);   // "04/13/08"
new Date().toString(f2);  // "04/13/08"

var date = Date.parseExact("04/13/08", f2); // Sun Apr 13 2008

I also added .strftime() which will format a local Unix timestamp according to 
locale
settings.

Example

Date.strftime("%m/%d/%y", new Date());       // "04/13/08"
Date.strftime("c", "2008-04-13T17:52:03Z");  // "04/13/08"

I also added .strtotime() which will parse any textual datetime description 
into a
Unix timestamp. A Unix timestamp is the number of seconds that have elapsed 
since
January 1, 1970 (midnight UTC/GMT).

Example

Date.strtotime("04/13/08");              // 1208044800
Date.strtotime("1970-01-01T00:00:00Z");  // 0   

More information is available in the CHANGELOG 
(http://www.datejs.com/changelog).

The extras.js file is available in SVN at the following location
(http://www.datejs.com/svn/extras/).

Hope this helps.

Original comment by geoff%co...@gtempaccount.com on 14 Apr 2008 at 5:22

GoogleCodeExporter commented 8 years ago
Ok great. Although I'm a bit confused over what files I should be including?
Should I include core.js date-en-AU.js and extras.js ? And how would I go about
merging all of these into one packed file?

Original comment by balup...@gmail.com on 17 May 2008 at 12:40

GoogleCodeExporter commented 8 years ago
Just include the appropriate culture-specific file (date-en-AU.js) and then 
extras.js.

Example

<script type="text/javascript" src="date-en-AU.js"></script>
<script type="text/javascript" src="extras.js"></script>

The culture-specific file (date-en-US.js) already includes core.js. 

Each culture-specific file is made of the following:

1. A CultureInfo file (this is culture specific)
2. core.js
3. parser.js
4. sugarpak.js

A compressed version of extras.js is provided in the /build/ folder. Probably 
the
easiest thing to do to merge extras.js into date-en-AU.js would be to 
copy/paste the
contents of the /build/extras.js into the end of /build/date-en-AU.js.

Hope this helps.

Original comment by geoff%co...@gtempaccount.com on 17 May 2008 at 8:47