You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@eliperelman : Date without "new" returns the current date for me. @jed : To extract the timezone, we could split ([+-]) too, but I don't see how to fit this in the rest of the bytes; we'd need to find out the difference to the current timezone, too and add/subtract it to/from the hours, too.
Alas, not. Either would it need a regexp to parse the whole string at once, which is 53 bytes long, and/or it would need a callback which resolves the month name, too, a part which currently takes amazing 41 bytes, add the 2 function statements and the new Date() and you're well over 140 bytes. It would look something like this:
function(a){return new Date(a.replace(/\w+ \w(\w+) (\d+) (\d+) (\d+):(\d+):(\d+) \w+(.\d+)/,function(a){a=arguments;[a[0],a[2]]=[a[2],a[0]];a[1]="anebarapayunulugepctovec".search(a[1])/2;return a.join(' ')}))}
Which does not yet take care of the timezone, btw.
@jed: I just found out that new Date([string]) internally calls Date.parse - so if it was not available anyway, we could only use eval for call will not work on new Date, thus enlargening the function quite a bit. Anyway, I will try to get Timezone handling inside this later.
Maybe this will help somehow for timezones: var timezone = -7; var d = new Date(); d.setUTCFullYear(2011, 6, 1) /* 1 Jul 2011 */ d.setUTCHours(1 + timezone, 0, 0) /* 01:00:00 UTC -7 hours */ console.log(d.toUTCString()); // Thu, 30 Jun 2011 18:00:00 GMT
Works well in IE6+, Fx, Op, node.js
Date.parse has been around since ES1 making a fallback seems a bit out of place. Also the workings of ES5/5.1 Date.parse are a bit too complex to fit in 140bytes.
nice work! i wonder if the 140bytes wizards can golf enough room in for
Date.parse=Date.parse||...
or timezones.