Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed to pass specs. Added Date.extras.parse specs.

  • Loading branch information...
commit b564dca640661e31595cf5960b9453a18edc679f 1 parent 1660023
Scott Kyle authored
View
47 Source/Native/Date.Extras.js
@@ -80,49 +80,6 @@ $extend(Date, {
});
-Date.parsePatterns = [
-
- {
- // "1999-12-31", "1999-12-31 11:59pm", "1999-12-31 23:59:59"
- re: /^(\d{4})[\.\-\/](\d{1,2})[\.\-\/](\d{1,2})(?:,?\s(\d{1,2})(?:[:.](\d{1,2}))?(?:[:.](\d{1,2}))?\s?([a-z]{2})?)?$/,
- handler: function(bits){
- var d = new Date(bits[1], bits[2] - 1, bits[3]);
- if (bits[4]){
- d.set({
- hr: bits[4],
- min: bits[5] || 0,
- sec: bits[6] || 0
- });
- if (bits[7]) d.set('ampm', bits[7]);
- }
- return d;
- }
- },
-
- {
- // "12.31.08", "12-31-08", "12/31/08", "12.31.2008", "12-31-2008", "12/31/2008"
- // above plus "10:45pm" ex: 12.31.08 10:45pm
- re: /^(\d{1,2})[\.\-\/](\d{1,2})(?:[\.\-\/](\d{2,4}))?(?:,?\s(\d{1,2})(?:[:.](\d{1,2}))?(?:[:.](\d{1,2}))?\s?([a-z]{2})?)?$/,
- handler: function(bits){
- var d = new Date().set({
- mo: bits[Date.orderIndex('month')] - 1,
- date: bits[Date.orderIndex('date')]
- });
- if (bits[3]) d.set('year', bits[3]);
- if (bits[4]){
- d.set({
- hr: bits[4],
- min: bits[5] || 0,
- sec: bits[6] || 0
- });
- if (bits[7]) d.set('ampm', bits[7]);
- }
- return Date.fixY2K(d);
- }
- }
-
-];
-
Date.parsePatterns.extend([
{
@@ -150,7 +107,7 @@ Date.parsePatterns.extend([
{
// "31st December", "31 Dec 1999", "31 Dec 1999 11:59pm"
- re: /^(\d{1,2})(?:st|nd|rd|th)?\s([a-z]+)(?:,?\s(\d{4}))?(,?\s\d{1,2}(?:[:.]\d{1,2})?(?:[:.]\d{1,2})?\s?[a-z]{2}?)?$/i,
+ re: /^(\d{1,2})(?:st|nd|rd|th)?\s([a-z]+)(?:,?\s(\d{4}))?(,?\s\d{1,2}(?:[:.]\d{1,2})?(?:[:.]\d{1,2})?\s?(?:[a-z]{2})?)?$/i,
handler: function(bits){
var str = (bits[3] || new Date().get('year')) + '-' + (Date.parseMonth(bits[2], true) + 1) + '-' + bits[1];
if (bits[4]) str += bits[4];
@@ -160,7 +117,7 @@ Date.parsePatterns.extend([
{
// same as above with month and day switched
- re: /^([a-z]+)\s(\d{1,2})(?:st|nd|rd|th)?(?:,?\s(\d{4}))?(,?\s\d{1,2}(?:[:.]\d{1,2})?(?:[:.]\d{1,2})?\s?[a-z]{2}?)?$/i,
+ re: /^([a-z]+)\s(\d{1,2})(?:st|nd|rd|th)?(?:,?\s(\d{4}))?(,?\s\d{1,2}(?:[:.]\d{1,2})?(?:[:.]\d{1,2})?\s?(?:[a-z]{2})?)?$/i,
handler: function(bits){
var str = (bits[3] || new Date().get('year')) + '-' + (Date.parseMonth(bits[1], true) + 1) + '-' + bits[2];
if (bits[4]) str += bits[4];
View
5 Source/Native/Date.js
@@ -347,9 +347,10 @@ $extend(Date, {
},
parsePatterns: [
+
{
// "1999-12-31", "1999-12-31 11:59pm", "1999-12-31 23:59:59"
- re: /^(\d{4})[\.\-\/](\d{1,2})[\.\-\/](\d{1,2})(?:,?\s(\d{1,2})(?:[:.](\d{1,2}))?(?:[:.](\d{1,2}))?\s?([a-z]{2})?)?$/,
+ re: /^(\d{4})[\.\-\/](\d{1,2})[\.\-\/](\d{1,2})(?:,?\s(\d{1,2})(?:[:.](\d{1,2}))?(?:[:.](\d{1,2}))?\s?([a-z]{2})?)?$/i,
handler: function(bits){
var d = new Date(bits[1], bits[2] - 1, bits[3]);
if (bits[4]){
@@ -367,7 +368,7 @@ $extend(Date, {
{
// "12.31.08", "12-31-08", "12/31/08", "12.31.2008", "12-31-2008", "12/31/2008", "12.31", "12-31", "12/31"
// above plus "10:45pm" ex: 12.31.08 10:45pm
- re: /^(\d{1,2})[\.\-\/](\d{1,2})(?:[\.\-\/](\d{2,4}))?(?:,?\s(\d{1,2})(?:[:.](\d{1,2}))?(?:[:.](\d{1,2}))?\s?([a-z]{2})?)?$/,
+ re: /^(\d{1,2})[\.\-\/](\d{1,2})(?:[\.\-\/](\d{2,4}))?(?:,?\s(\d{1,2})(?:[:.](\d{1,2}))?(?:[:.](\d{1,2}))?\s?([a-z]{2})?)?$/i,
handler: function(bits){
var d = new Date().set({
mo: bits[Date.orderIndex('month')] - 1,
View
16 Specs/Native/Date.Extras.js
@@ -86,3 +86,19 @@ describe('Date.timeAgoInWords', {
}
});
+
+describe('Date.extras.parse', {
+
+ 'should parse a string value into a date': function(){
+ MooTools.lang.list().each(function(lang){
+ MooTools.lang.setLanguage(lang);
+ var d = new Date(2000, 11, 2, 0, 0, 0, 0);
+ value_of(Date.parse(d.format('%b %d %Y')).clearTime()).should_be(d);
+ value_of(Date.parse(d.format('%d %B %Y')).clearTime()).should_be(d);
+ d = new Date(2000, 11, 2, 22, 45, 0, 0);
+ value_of(Date.parse(d.format('%B %d %Y %X')).set('sec',0).set('ms',0)).should_be(d);
+ value_of(Date.parse(d.format('%d %b %Y %H:%M')).set('sec',0).set('ms',0)).should_be(d);
+ });
+ }
+
+});
Please sign in to comment.
Something went wrong with that request. Please try again.