Pure Programmer
Blue Matrix


Cluster Map

Project: Duration Class

Write a mutable class to represent a time duration. Your class should represent time durations in the following units: ns, µs, ms, s, min, hour, day, week, month, year. Use an enumeration to represent the time duration units. You should have a default constructor that sets the internal value to 0. Write a setter that takes a value and an enumeration value for units. Include a getter that takes an enumeration value for units and returns the value in that measurement unit.

Output
$ node DurationClass.js 1230000000 ns 1230000 µs 1230 ms 1.23 sec 0.0205 min 0.00034166666666666666 hour 0.000014236111111111111 day 0.000002033730158730159 week 4.677161761350673e-7 month 3.897634801125561e-8 year 31557600000000000 ns 31557600000000 µs 31557600000 ms 31557600 sec 525960 min 8766 hour 365.25 day 52.17857142857143 week 12 month 1 year 1 ns 0.001 µs 0.0000010000000000000002 ms 1e-9 sec 1.6666666666666667e-11 min 2.777777777777778e-13 hour 1.1574074074074075e-14 day 1.6534391534391536e-15 week 3.8025705376834745e-16 month 3.1688087814028956e-17 year

Solution