Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.
This repository was 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

Description

@tburny

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions