You need to sign in or sign up before continuing.×
Beta

Time Conversion: 12s and 24s

45 of 54colbydauph
Description
Loading description...
Strings
Date Time
Regular Expressions
Fundamentals
  • Please sign in or sign up to leave a comment.
  • farhanaditya Avatar

    The 12-hours format for 12:XX has multiple versions worldwide. It can be 12:XX PM or 12:XX AM. In this kata, it should be specified which one should be used.

    In one of the example of 12-hours format, there is a 12:59 AM. So let's assume this kata uses 12:XX AM format. However, on one of the 12 -> 24 -> 12 tests, it gave me 12:00:24PM as the input, but expected me to return 12:00:24am as the output (when reverting back to 12).

    What's the logic here? It against one of the rules: Format Preservation.

  • Voile Avatar

    Throwing a string is not a good practice at all. The normal way is to throw a new Error().

    And sure you can just check if any error is thrown? There's no need to forcefully make one only throws a specific error unless that's clarity requirements (which you have none of them, your error requirements are nothing but error and they're even strings).

  • wthit56 Avatar

    It's a good kata, and I enjoyed tackling it. There are just a couple of things you could change to make things a littler easier to understand and debug:

    As it is, the formatting and spacing is kind of an afterthought, but in actuality, this is the main part of the kata. There are other problems making it hard to parse the instructions first time, also. With just a bit of rejigging and moving stuff around, the understandability would really be helped, I think.

    The .normalize() method, while nice, does tend to give the coder cryptic errors from time to time. If a returned value is not a string, a test should fail or error should be thrown explicitly stating that problem, rather than an unrelated error arising after the fact, leaving the coder to scratch their heads, print out the inner-workings of .normalize(), re-read the instructions, and so-on until they figure out what's going on.

    Messages like "'undefined' is not a valid time" is a bit too sparse--and misleading--to be that helpful. First, you could actually say that a value was returned, and that an error was expected. Test.expectError is perfect for this. Second, the input value is always wrapped in ' characters, when in reality, the value is rarely a string at all. You can use Test.inspect(value) to generate a readable string of the value in question to use in your errors or test failure messages.

    But again, good job on the kata so far!

  • user2713389 Avatar

    Why throw 'error'? Should rather use throw new Error();

  • mfferreira Avatar

    On the 24 > 12 > 24 tests, 24:XX is not a valid 24h format

  • Abbe Avatar

    The only real problem I had (except for spacing and such) was that in the 24->12->24 test phase, I got as original input '24:12:15', which isn't a valid 24-hour time. The function for generating random 24-hour times isn't visible, so I can't really check it.

    Otherwise, it would have been nice with some static tests to check the edge cases. In particular around 00h and 12h.

    Nice kata!

  • osuushi Avatar

    Spacing and case may vary in your inputs, but both will be disregarded in the official tests. String.prototype.normalize has been provided to handle this if you wish to use it.

    This is strangely phrased, and makes it sound like handling case and spacing flexibly is optional, which it isn't.

    Also, as jacobb mentioned, you ought to include static edge cases in addition to the random tests. Otherwise, a partially wrong solution can easily pass just by getting lucky.

  • jacobb Avatar

    This comment has been hidden.