Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix a bug in toString()

If the format string to use was not specified, a default format was used, but
the tz parameter was discarded.
  • Loading branch information...
commit 9d333bc01b14383595ead7b776bc241f6a71184c 1 parent 66754a5
@dtrebbien dtrebbien authored
Showing with 7 additions and 1 deletion.
  1. +6 −0 spec/date.spec.js
  2. +1 −1  src/date.js
View
6 spec/date.spec.js
@@ -39,6 +39,12 @@ describe('timezoneJS.Date', function () {
expect(date.toString('MMM dd yyyy HH:mm:ss k Z', 'Indian/Cocos')).toEqual('Feb 28 2011 07:14:22 PM CCT');
});
+ it('should use a default format with the given tz', function () {
+ var date = new timezoneJS.Date(2012, 7, 30, 10, 56, 0, 0, 'America/Los_Angeles');
+ expect(date.toString(null, 'Etc/UTC')).toEqual(date.toString('yyyy-MM-dd HH:mm:ss', 'Etc/UTC'));
+ expect(date.toString(null, 'America/New_York')).toEqual(date.toString('yyyy-MM-dd HH:mm:ss', 'America/New_York'));
+ });
+
it('should convert dates from UTC to a timezone correctly', function () {
var date = new timezoneJS.Date(2011,1,28,12,44,22,172,'Etc/UTC');
date.setTimezone('America/Los_Angeles');
View
2  src/date.js
@@ -333,7 +333,7 @@
// Allows different format following ISO8601 format:
toString: function (format, tz) {
// Default format is the same as toISOString
- if (!format) return this.toString('yyyy-MM-dd HH:mm:ss');
+ if (!format) format = 'yyyy-MM-dd HH:mm:ss';
var result = format;
var tzInfo = tz ? timezoneJS.timezone.getTzInfo(this.getTime(), tz) : this.getTimezoneInfo();
var _this = this;
Please sign in to comment.
Something went wrong with that request. Please try again.