dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

fix: Pad formatted year string with zeros

Open at-soft opened this issue 6 years ago • 4 comments

This pull request fixes formatting of date with pattern "YYYY" for years less than 1000

at-soft avatar May 13 '19 15:05 at-soft

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (f3e671f) to head (e1e64bf). Report is 557 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #597   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          154       154           
  Lines          982       982           
  Branches       140       140           
=========================================
  Hits           982       982           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-io avatar May 14 '19 09:05 codecov-io

I just stumbled into this issue. It would be nice to get this merged in

hc-12 avatar Aug 13 '19 06:08 hc-12

Not really good. You can pad number on demand in your particular project but internationally years before 1000 are used unpadded

cokkto avatar Jan 27 '20 16:01 cokkto

Not really good. You can pad number on demand in your particular project but internationally years before 1000 are used unpadded

My intention is to keep compatibility with moment.js API, which has YYYY format for 4-digit years and Y to display unpadded year. Moreover, current formatting leads to some errors like

const initial = new Date('0001-01-01');
const initial_dayjs = dayjs(initial);
const formated_initial = initial_dayjs.format('YYYY-MM-DD'); // produces 1-01-01
const parsed = dayjs(formated_initial);
const formated_result = initial_dayjs.format('YYYY-MM-DD'); // produces 2001-01-01

at-soft avatar Mar 11 '20 13:03 at-soft