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 66a3955
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 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
22 changes: 11 additions & 11 deletions test/format.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ 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)
})
})
Expand All @@ -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)
})
})
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'
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 66a3955

Please sign in to comment.