Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Fix/improve date format #67

Merged
merged 3 commits into from Feb 13, 2018
Merged

Fix/improve date format #67

merged 3 commits into from Feb 13, 2018

Conversation

mburak
Copy link
Contributor

@mburak mburak commented Feb 9, 2018

This PR changes the date format we are using in the rules from ISO 8601 to PHP date format so it's compatible with the Facebook Instant Articles SDK. It also adds a link to the PHP Date documentation.

image

@@ -46,7 +47,7 @@ class DateTimeFormatPicker extends React.Component<Props, State> {
return null;
}
let expectedDateTime = attributes.find(attr => attr.name == attribute);
return expectedDateTime ? expectedDateTime.value : null;
return expectedDateTime ? expectedDateTime.value.trim() : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Contributor

@pestevez pestevez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for these changes, @mburak! The issue you are fixing is a show-stopper.

I have mixed feelings about replacing a standard format with the PHP one (I believe the SDK should be able to handle the ISO format instead) but given the importance of fixing the dates, I am fine with it.

I believe that before merging we should avoid adding new lint warnings, and I strongly recommend adding some tests to make sure it is clear that we are using the PHP date format.

@@ -55,15 +56,20 @@ class DateTimeFormatPicker extends React.Component<Props, State> {
if (this.expectedDateTime() != null) {
m = moment.parseZone(this.expectedDateTime());
if (m.isValid()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to keep the call to isValid?

@@ -26,7 +26,7 @@ export type JSONFormat = {

type RulePropertyJSON = {
attribute: ?string,
dateTimeFormat?: string,
format?: string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just out of curiosity, what triggered the change of name?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bug. This is the output format, and the SDK expects format. That explains why the preview never had the date =)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the SDK expects format, which was in fact what we were sending. I believe there was no need to change this name here, but it is not a show-stopper.

* @flow
*/

(function(m) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think there is a way to implement it by exporting as a module instead of as an iife?

*/
const moment = require('moment');

var formatMap = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we split the initialization here to avoid the lint warning?

a: 'a',
A: 'A',
B: function() {
var thisUTC = this.clone().utc(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also split the initialization here?

@@ -11,13 +11,14 @@
const React = require('react');
const classNames = require('classnames');
const moment = require('moment');
const phpDateTimeMomentFormat = require('../utils/phpDateTimeMomentFormat');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am getting an unused var warning here. Is there a way to avoid it? I understand that you are adding a function, so you need to load the file.

@pestevez pestevez assigned diegoquinteiro and unassigned pestevez Feb 13, 2018
@pestevez
Copy link
Contributor

@mburak I took the liberty to fix some of the linter warnings. Requesting now @diegoquinteiro to take a look.

@@ -26,7 +26,7 @@ export type JSONFormat = {

type RulePropertyJSON = {
attribute: ?string,
dateTimeFormat?: string,
format?: string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bug. This is the output format, and the SDK expects format. That explains why the preview never had the date =)

? 'textContent'
: 'innerContent',
format: rulePropertyJSON.dateTimeFormat,
rulePropertyJSON.type == RulePropertyTypes.DATETIME &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot remove the logic for dealing with empty attributes in other fields. The logic here should be:

  • If attribute came not null, use the attribute name.
  • If the attribute came null:
    • If the type is string, use 'textContent'
    • If the type is date, use 'dateTextContent'
    • Otherwise use 'innerContent'

Copy link
Contributor

@pestevez pestevez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add some tests, but as it is, it looks good to me. Thanks to all!

@pestevez pestevez merged commit 45bfd0c into master Feb 13, 2018
@pestevez pestevez deleted the php-date-format branch February 13, 2018 17:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants