Fix issues in GTime2str() and add unit test cases to verify correct behaviour. Follow-up to 3c914bc680 Closes #14316
3c914bc680