From 38ab3993189656b17ff20ac67ea13fef02be3e66 Mon Sep 17 00:00:00 2001 From: imed jaberi Date: Sat, 12 Oct 2024 17:00:03 +0100 Subject: [PATCH] fix: adapte the sign to pass for zero value to be positvie instead of negative --- format.js | 2 +- test/format.spec.js | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/format.js b/format.js index 7c41960..00725dc 100644 --- a/format.js +++ b/format.js @@ -68,7 +68,7 @@ function toOffset(offsetMinutes) { const absoluteOffset = Math.abs(offsetMinutes); const hours = toTwoDigits(Math.floor(absoluteOffset / 60)); const minutes = toTwoDigits(absoluteOffset % 60); - const sign = offsetMinutes >= 0 ? '-' : '+'; + const sign = offsetMinutes > 0 ? '-' : '+'; return `${sign}${hours}${minutes}`; } diff --git a/test/format.spec.js b/test/format.spec.js index 9c43d52..7b0123f 100644 --- a/test/format.spec.js +++ b/test/format.spec.js @@ -16,25 +16,25 @@ describe('toTwoDigits', () => { expect(toTwoDigits(value)).toBe(expected) }) - test('throws TypeError if provided value is Infinity', () => { + it('throws TypeError if provided value is Infinity', () => { expect(() => toTwoDigits(Infinity)).toThrow(TypeError) }) - test('throws TypeError if provided value is NaN', () => { + it('throws TypeError if provided value is NaN', () => { expect(() => toTwoDigits(NaN)).toThrow(TypeError) }) - test('throws TypeError if provided value is a decimal number', () => { + it('throws TypeError if provided value is a decimal number', () => { expect(() => toTwoDigits(0.99)).toThrow(TypeError) }) - test('throws TypeError if provided value is a string', () => { + it('throws TypeError if provided value is a string', () => { expect(() => toTwoDigits('0')).toThrow(TypeError) }) }) describe('toOffset', () => { - test.each([ + it.each([ { value: 480, expected: '-0800' }, { value: 0, expected: '+0000' }, { value: -180, expected: '+0300' }, @@ -42,19 +42,19 @@ describe('toOffset', () => { expect(toOffset(value)).toBe(expected) }) - test('throws TypeError if provided value is Infinity', () => { + it('throws TypeError if provided value is Infinity', () => { expect(() => toOffset(Infinity)).toThrow(TypeError) }) - test('throws TypeError if provided value is NaN', () => { + it('throws TypeError if provided value is NaN', () => { expect(() => toOffset(NaN)).toThrow(TypeError) }) - test('throws TypeError if provided value is a decimal number', () => { + it('throws TypeError if provided value is a decimal number', () => { expect(() => toOffset(60.5)).toThrow(TypeError) }) - test('throws TypeError if provided value is a string', () => { + it('throws TypeError if provided value is a string', () => { expect(() => toOffset('60')).toThrow(TypeError) }) }) @@ -77,19 +77,19 @@ describe('toShortMonth', () => { expect(toShortMonth(value)).toBe(expected) }) - test('throws TypeError for a non-valid month number', () => { + it('throws TypeError for a non-valid month number', () => { expect(() => toShortMonth(13)).toThrow(TypeError) }) }) describe('toCommonAccessLogDateFormat', () => { - test('correctly formats a date', () => { + it('correctly formats a date', () => { const date = new Date('2020-01-01T12:34:56Z') - const expectedValue = '01/Jan/2020:10:34:56 +0200' + const expectedValue = '01/Jan/2020:12:34:56 +0000' expect(toCommonAccessLogDateFormat(date)).toBe(expectedValue) }) - test('throws TypeError for non-Date value', () => { + it('throws TypeError for non-Date value', () => { expect(() => toCommonAccessLogDateFormat({})).toThrow(TypeError) }) }) \ No newline at end of file