Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Conversation

@markandey
Copy link
Collaborator

What ?

This Pull Request contains reviewable code from Intl.DateTimeFormat timezone polyfill.

How

Code Files

Polyfill code is split across 3 files.

  1. polyfill.js
  2. lookup-utill.js
  3. data-loader.js

src/code/polyfill.js

This contains polyfill code. i.e. in this file you would see prototype of Intl.DateTimeFormat and Date is modified to achieve polyfill.

src/code/lookup-utill.js

This file contains functions to get access to timezone data and locale data. To achieve DateTime formatting.

src/code/data-loader.js

This file contains functions unpack data from data file and loads into memory.

Data Files

  1. src/data/timezones/tzdata-america-los_angeles.js
    This data is downloaded from iana
  2. If Multiple timezone have same definitions they are deduped, into one.
  3. All untill timeStamps are indexed in an array.
  4. All offset is index in an rray
  5. isDst is represented as it is.
  6. All indeices and values in index array are base 32 strings.
   "America/Los_Angeles||0,0,0,1,1,1,2,0,0,3,1,1,4,0,0,5,1,1,6,1,1,7,0,0,8,1,1
   ---^--------------------^-^-^--------------------------------------------
   --timezone------------[untill32]-[offset32]--isdst---
 ------------------------timeStamps---offsets-----------------------------
  1. src/data/locales/locale-en-US-POSIX.js
    This is transformation of CLDR data.
    Compression is achieved by indexing the words in zoneNameIndex array and for every metaZone providing 4 values for shortStandard, shortDayLight, longStandard, longDayLight. separated by | and every word is separated by , . zoneNameIndex is sorted by words' frequency so that high frequency words represented by small number.
    e.g.
"Samoa": "30,0,2,0,1|30,0,4,0,1||",
--^--------^-----------^------ --^              

@yahoocla
Copy link

CLA is valid!

@markandey
Copy link
Collaborator Author

@jlecomte @juandopazo

Copy link

@jlecomte jlecomte left a comment

Choose a reason for hiding this comment

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

I would use the es2015 preset in your `.babelrc'. Also, I suggest you use the same eslint config we use for our internal projects, to ensure consistent and strict code styling. I noticed your test files use tabs, but your source files use 4 white spaces for indentation. Please be consistent across the repo (4 white spaces) I will do another review when all these concerns have been addressed. Thanks!

Choose a reason for hiding this comment

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

Shouldn't we throw here?

Choose a reason for hiding this comment

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

Usually, this is done as part of the while statement above...

Choose a reason for hiding this comment

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

Shouldn't we throw here?

Choose a reason for hiding this comment

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

What's Ob? If we throw instead of using console.warn, this is true. Otherwise, it's incorrect since the function can return undefined...

Choose a reason for hiding this comment

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

Missing extra line at the end...

Choose a reason for hiding this comment

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

Use const or let on each line...

Choose a reason for hiding this comment

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

Use const or let on each line...

Choose a reason for hiding this comment

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

Use const or let on each line...

Choose a reason for hiding this comment

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

Use const or let on each line...

Choose a reason for hiding this comment

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

Remove "Returns" :)

@markandey markandey force-pushed the pr branch 4 times, most recently from 8936944 to 3b7e83e Compare January 20, 2017 00:09
@markandey
Copy link
Collaborator Author

@jlecomte Addressed them all.

Copy link
Contributor

Choose a reason for hiding this comment

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

parseInt(x, 32) 😮

Copy link
Collaborator Author

@markandey markandey Jan 24, 2017

Choose a reason for hiding this comment

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

Yes data files contains index and timestamp values as base32 represented strings.
I guess You mean, why base is 32 and not 10 ??

Copy link
Contributor

@juandopazo juandopazo Jan 23, 2017

Choose a reason for hiding this comment

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

If you're ever concerned about the performance of this code, this is doing a lot of mutations, where you could just be having a while loop where you increment a counter by 3...

let result = [], i = 0;
while (i < arr.length) {
  result.push([arr[i], arr[i + 1], arr[i + 2]);
  i += 3;
}

And it wouldn't be harder to understand.

@juandopazo
Copy link
Contributor

Overall, I really wish there were more comments everywhere. There's a lot of code that is based on some internal conventions and data structure, so anyone looking at it would have a hard time following it. Some well placed comments would help a lot.

@markandey markandey force-pushed the pr branch 2 times, most recently from 56773e3 to be92a49 Compare January 25, 2017 23:31
@markandey
Copy link
Collaborator Author

@juandopazo @jlecomte

  1. Added lot of comments all around.
  2. Polyfill class now inherits original class , which makes instanceof test pass.

@jlecomte
Copy link

@markandey I skimmed the repo and this PR. Overall, it looks fine to me 👍 but I will let @juandopazo do one final pass.

@markandey
Copy link
Collaborator Author

@juandopazo I did test that static functions are preserved from original Intl.DateTimeFormat.
Lets get this merged to proceed !

@markandey markandey force-pushed the pr branch 2 times, most recently from 5a7baf9 to d226721 Compare January 31, 2017 20:47
@juandopazo
Copy link
Contributor

@markandey I took a second look. Overall looks much better! There's still a few issues I noted inline. After those, let's merge this and make it public so we can get some feedback from the community.

@markandey markandey merged commit 3e29029 into master Feb 3, 2017
markandey added a commit that referenced this pull request Feb 3, 2017
Merge pull request #1 from yahoo/pr
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants