title: The best way to create a time converter with an enum
body: <p>I have some doubts for creating a time converter.
  I created the class Time wich can convert a time in milliseconds, seconds, 
  minutes, hours and days. Although I did it easily, I'm not sure my code is 
  clean. Actually, I created the enum DurationType, and each element contains
  the product that permits to convert it in milliseconds. That allows me to
  have a code of 30 lines, but it seems weird to multiply a value by DurationType.HOUR for example.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>"use strict";
  
  const DurationType = {
  DAY: 24*60*60*1000,
  HOUR: 60*60*1000,
  MINUTE: 60*1000,
  SECOND:1000,
  MILLISECOND: 1
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>"use strict";
  
  class Time {
   constructor(value, type=DurationType.MILLISECOND) {
    this.setValue(value, type);
   }
  
   getValueIn(type=DurationType.MILLISECOND) {
    return convertTo(this.value, DurationType.MILLISECOND, type);
   }
  
   setValue(value, type) {
    this.value = Time.convertTo(value, type, DurationType.MILLISECOND);
   }
  
   static convertTo(value, type, wantedType) {
    if(!(wantedType instanceof DurationType))
     return error("wantedType isn't an instance of DurationType", 1); // display the error message and return 1
    return value*type/wantedType;
   }
  }</code></pre>
  </div>
  </div>
  </p>