Skip to content

Commit 2d3afd5

Browse files
author
Therapon Skoteiniotis
committed
Merge branch 'kadishmal-hotfix-66'
* kadishmal-hotfix-66: fix(source): Fix #66: Zulu timestamps fails with Error: Invalid decimal 00.000Z.
2 parents 0201ebc + 520f4e7 commit 2d3afd5

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/IonTimestamp.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
// undefined, empty or a null image it returns the timestamp NULL.
3131

3232
import { Decimal } from "./IonDecimal";
33-
import { is_digit } from "./IonText";
3433
import { isNumber } from "./IonUtilities";
3534
import { isString } from "./IonUtilities";
3635
import { isUndefined } from "./IonUtilities";
@@ -178,7 +177,7 @@ function to_4_digits(v: number) : string {
178177
function read_unknown_digits(str: string, pos: number) : string {
179178
let i: number = pos;
180179
for (; i < str.length; i++) {
181-
if (!isNumber(str.charCodeAt(i))) {
180+
if (!isNumber(parseInt(str[i], 10))) {
182181
break;
183182
}
184183
}
@@ -501,7 +500,10 @@ export class Timestamp {
501500
break;
502501
// 1234-67-89T12:45:78.dddd
503502
case States.FRACTIONAL_SECONDS:
504-
seconds = Decimal.parse(str.substr(17, pos - 17));
503+
const START_POSITION_OF_SECONDS = 17;
504+
505+
seconds = Decimal.parse(str.substring(START_POSITION_OF_SECONDS, pos));
506+
505507
break;
506508
case States.OFFSET:
507509
break;

src/IonUtilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* A collection of general language-level helper methods.
1616
*/
1717
export function isNumber(value: any) : value is number {
18-
return typeof(value) == 'number';
18+
return typeof(value) == 'number' && !isNaN(value);
1919
}
2020

2121
export function isString(value: any) : value is string {

tests/unit/IonTimestampTest.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@
1717
const assert = require('intern/chai!assert');
1818
const ion = require('dist/amd/es6/Ion');
1919

20-
var suite = {
20+
let suite = {
2121
name: 'Timestamp'
2222
};
2323

24-
var parseTest = function(name, timestamp) {
24+
const parseTest = function(name, timestamp) {
2525
suite[name] = function() {
2626
ion.Timestamp.parse(timestamp);
2727
}
28-
}
28+
};
2929

3030
parseTest('Parses year', '2017T');
3131
parseTest('Parses month', '2017-02T');
32+
// Seconds are optional, but local offset is not.
33+
parseTest('Parses date and time with only hour and minutes', '2007-02-23T12:14Z');
34+
parseTest('Parses timestamp: The same instant in UTC ("zero" or "zulu")', '2017-05-01T01:00:00.000Z');
3235

3336
registerSuite(suite);
3437
}

0 commit comments

Comments
 (0)