Socket
Socket
Sign inDemoInstall

convert-time

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.2.0

26

index.js

@@ -5,7 +5,7 @@ module.exports = function (time, format) {

function getTwoDigitHour(hour) {
if (hour.length === 1) {
return '0' + hour;
function maybePrependZero(str) {
if (str.length === 1) {
return '0' + str;
} else {
return hour;
return str;
}

@@ -33,3 +33,3 @@ }

if (! format) {
format = 'hh:mm';
format = 'hh:MM';
}

@@ -39,7 +39,9 @@

return format.replace('hh', parseInt(hour)+12)
.replace('mm', minute);
.replace('mm', minute)
.replace('MM', maybePrependZero(minute));
} else {
return format.replace('hh', hour)
.replace('HH', getTwoDigitHour(hour))
.replace('mm', minute);
.replace('HH', maybePrependZero(hour))
.replace('mm', minute)
.replace('MM', maybePrependZero(minute));
}

@@ -57,3 +59,3 @@ }

if (! format) {
format = 'hh:mm a';
format = 'hh:MM a';
}

@@ -63,4 +65,5 @@

return format.replace('hh', parseInt(hour)-12)
.replace('HH', getTwoDigitHour(hour))
.replace('HH', maybePrependZero(hour))
.replace('mm', minute)
.replace('MM', maybePrependZero(minute))
.replace('a', 'pm')

@@ -70,4 +73,5 @@ .replace('A', 'PM');

return format.replace('hh', hour)
.replace('HH', getTwoDigitHour(hour))
.replace('HH', maybePrependZero(hour))
.replace('mm', minute)
.replace('MM', maybePrependZero(minute))
.replace('a', getPeriod(hour))

@@ -74,0 +78,0 @@ .replace('A', getPeriod(hour).toUpperCase());

{
"name": "convert-time",
"version": "0.1.0",
"version": "0.2.0",
"description": "Convert 24-hour time to 12-hour time and vice versa",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -43,9 +43,16 @@ # Convert-time

the front. (e.g. `3` becomes `03`)
* `mm` - Minute.
* `mm` - Minute. It can be one or two digits.
* `MM` - Minute. It is always two digits. If one digit, `0` is appended in
the front. (e.g. `9` becomes `09`)
* `a` - Period. `am` or `pm`.
* `A` - Capitalized period. `AM` or `PM`.
Default values for format are:
`hh:MM` for 12-hour to 24-hour conversion.
`hh:MM a` for 24-hour to 12-hour conversion.
## License
MIT

@@ -126,2 +126,13 @@ var convertTime = require('../index');

});
describe("with format 'hh:MM'", function() {
it("translates 2:8 am to 02:08", function() {
var result = convertTime('2:8 am', 'hh:MM');
expect(result).to.equal('2:08');
});
it("translates 3:8 pm to 02:08", function() {
var result = convertTime('3:8 pm', 'hh:MM');
expect(result).to.equal('15:08');
});
});
});

@@ -147,5 +158,5 @@

describe("with format 'HH:mm a'", function() {
describe("with format 'HH:MM a'", function() {
it("translates 2:00 to 02:00 am", function() {
var result = convertTime('2:00', 'HH:mm a');
var result = convertTime('2:00', 'HH:MM a');
expect(result).to.equal('02:00 am');

@@ -155,9 +166,21 @@ });

describe("with format 'hh:mm A'", function() {
it("translates 2:00 to 02:00 AM", function() {
var result = convertTime('2:00', 'hh:mm A');
describe("with format 'hh:MM A'", function() {
it("translates 2:00 to 2:00 AM", function() {
var result = convertTime('2:00', 'hh:MM A');
expect(result).to.equal('2:00 AM');
});
it("translates 2:8 to 2:8 AM", function() {
var result = convertTime('2:8', 'hh:mm A');
expect(result).to.equal('2:8 AM');
});
});
describe("with format 'hh:MM A'", function() {
it("translates 2:8 to 2:08 AM", function() {
var result = convertTime('2:8', 'hh:MM A');
expect(result).to.equal('2:08 AM');
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc