Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ measurement('Distance').convert(1)
measurement('Speed').convert(10)
.from(measurement.Unit.Speed.KILOMETRE_PER_HOUR)
.to(measurement.Unit.Speed.METRES_PER_SECOND); // returns 36

measurement('Mass').convert(1)
.from(measurement.Unit.Mass.KILOGRAM)
.to(measurement.Unit.Mass.GRAM); // returns 1000
```


Expand Down
60 changes: 57 additions & 3 deletions measurement.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
KELVIN: 'k'
},
Duration: {
YEAR: 'year',
WEEK: 'week',
DAY: 'day',
HOUR: 'h',
MINUTE: 'm',
SECOND: 's'
Expand Down Expand Up @@ -189,20 +192,71 @@
}
},
Duration: {
'year': {
key: UNIT.Duration.YEAR,
base: 's',
factor: 31557600,
name: {
en: 'Year',
},
plural: {
en: 'Years'
}
},
'week': {
key: UNIT.Duration.WEEK,
base: 's',
factor: 604800,
name: {
en: 'Week',
},
plural: {
en: 'Weeks'
}
},
'day': {
key: UNIT.Duration.DAY,
base: 's',
factor: 86400,
name: {
en: 'Day',
},
plural: {
en: 'Days'
}
},
'h': {
key: UNIT.Duration.HOUR,
base: 's',
factor: 3600
factor: 3600,
name: {
en: 'Hour',
},
plural: {
en: 'Hours'
}
},
'm': {
key: UNIT.Duration.MINUTE,
base: 's',
factor: 60
factor: 60,
name: {
en: 'Minute',
},
plural: {
en: 'Minutes'
}
},
's': {
key: UNIT.Duration.SECOND,
base: null,
factor: 1
factor: 1,
name: {
en: 'Second',
},
plural: {
en: 'Seconds'
}
}
},
Mass: {
Expand Down
12 changes: 12 additions & 0 deletions test/unit/mJs.convert.DurationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ describe("measurement.Unit.Duration", function() {
convertDuration(2).from(durationUnit.HOUR).to(durationUnit.SECOND)
).toBe(7200);
});

it("returns 1 for convert( 365.25 ).from( Duration.DAY ).to( Duration.YEAR )", function() {
expect(
convertDuration(365.25).from(durationUnit.DAY).to(durationUnit.YEAR)
).toBe(1);
});

it("returns 7 for convert( 1 ).from( Duration.WEEK ).to( Duration.DAY )", function() {
expect(
convertDuration(1).from(durationUnit.WEEK).to(durationUnit.DAY)
).toBe(7);
});

});
});
Expand Down