Skip to content

Commit

Permalink
fix: adapte the sign to pass for zero value to be positvie instead of…
Browse files Browse the repository at this point in the history
… negative
  • Loading branch information
3imed-jaberi committed Oct 12, 2024
1 parent 30b4a7b commit 444c63a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
Expand Down
26 changes: 13 additions & 13 deletions test/format.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,45 @@ 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' },
])('returns $expected for $value', ({ value, expected }) => {
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)
})
})
Expand All @@ -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:13:34:56 +0100'
expect(toCommonAccessLogDateFormat(date)).toBe(expectedValue)
})

test('throws TypeError for non-Date value', () => {
it('throws TypeError for non-Date value', () => {
expect(() => toCommonAccessLogDateFormat({})).toThrow(TypeError)
})
})

0 comments on commit 444c63a

Please sign in to comment.