diff options
author | Shinya Maeda <shinya@gitlab.com> | 2017-11-06 23:43:10 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2017-11-06 23:43:10 +0900 |
commit | b4d167a8f78509e241639e560ee1fed545d2dbc1 (patch) | |
tree | ad31164a4fe19d7c3dbc7d9e9f1d3ee6e3e65637 /app/assets/javascripts/lib/utils/datefix.js | |
parent | c5377b97968ba9edefe7766dac77cc9fbbaa4e2c (diff) | |
parent | d4ceec9d47a7da5fa17cb6e161ac491e13fcb8bd (diff) | |
download | gitlab-ce-feature/sm/3691-expose-per-project-pipeline-id.tar.gz |
Merge branch 'master' into feature/sm/3691-expose-per-project-pipeline-idfeature/sm/3691-expose-per-project-pipeline-id
Diffstat (limited to 'app/assets/javascripts/lib/utils/datefix.js')
-rw-r--r-- | app/assets/javascripts/lib/utils/datefix.js | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/app/assets/javascripts/lib/utils/datefix.js b/app/assets/javascripts/lib/utils/datefix.js index 990dc3f6d1a..e98c9068367 100644 --- a/app/assets/javascripts/lib/utils/datefix.js +++ b/app/assets/javascripts/lib/utils/datefix.js @@ -1,8 +1,29 @@ -const DateFix = { - dashedFix(val) { - const [y, m, d] = val.split('-'); - return new Date(y, m - 1, d); - }, + +export const pad = (val, len = 2) => (`0${val}`).slice(-len); + +/** + * Formats dates in Pickaday + * @param {String} dateString Date in yyyy-mm-dd format + * @return {Date} UTC format + */ +export const parsePikadayDate = (dateString) => { + const parts = dateString.split('-'); + const year = parseInt(parts[0], 10); + const month = parseInt(parts[1] - 1, 10); + const day = parseInt(parts[2], 10); + + return new Date(year, month, day); }; -export default DateFix; +/** + * Used `onSelect` method in pickaday + * @param {Date} date UTC format + * @return {String} Date formated in yyyy-mm-dd + */ +export const pikadayToString = (date) => { + const day = pad(date.getDate()); + const month = pad(date.getMonth() + 1); + const year = date.getFullYear(); + + return `${year}-${month}-${day}`; +}; |