Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

RFC 2616 Dates cannot be parsed if default locale is not English #561

Open
tburny opened this issue Oct 15, 2018 · 0 comments
Open

RFC 2616 Dates cannot be parsed if default locale is not English #561

tburny opened this issue Oct 15, 2018 · 0 comments

Comments

@tburny
Copy link

tburny commented Oct 15, 2018

Problem

datetime properties with a valid datetime like Sun, 28 Feb 2016 16:41:41 GMT cause a validation error if the Java default Locale is not English.

types: 
  Car:
      dateTimeRFC2616: 
        type: datetime
        format: rfc2616
        example: "Sun, 28 Feb 2016 16:41:41 GMT"

(Source: https://github.com/phoenixnap/springmvc-raml-plugin/blob/master/src/test/resources/ramls/github/issue-253.raml)

This line is missing a preset locale, probably English:

private static DateTimeFormatter rfc2616Formatter = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss zzz");

so it should be

    private static DateTimeFormatter rfc2616Formatter = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss zzz").withLocale(Locale.ENGLISH);

as demonstrated by the following

Test case

package org.raml.yagi.framework.util;

import org.junit.Test;
import java.util.Locale;

import static org.junit.Assert.assertTrue;

public class DateUtilsTest {

    @Test
    public void isValidDate() {
        Locale.setDefault(Locale.GERMANY);
        assertTrue("The date is always valiid", DateUtils.isValidDate("Sun, 28 Feb 2016 16:41:41 GMT", DateType.datetime, "rfc2616"));
    }
}

See also

#272 Tests failö on non-English locale

Aha! Link: https://mulesoft-roadmap.aha.io/features/APIRAML-46

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant