Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add customParseFormat support for isoweek #2709

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

amoydavid
Copy link

  1. add customParseFormat support for isoweek(W and WW)
  2. fix test for weekOfYear

@@ -100,6 +100,8 @@ const expressions = {
}],
w: [match1to2, addInput('week')],
ww: [match2, addInput('week')],
W: [match1to2, addInput('week')],
WW: [match2, addInput('week')],
Copy link
Owner

Choose a reason for hiding this comment

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

seems there no logic dealing with ISOWeek?

Copy link
Author

Choose a reason for hiding this comment

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

In the customParseFormat scenario, similar to the code in pull request #2705, it's sufficient to support parsing uppercase W/WW for ISO week notation. For stricter validation, one could additionally check if the week number exceeds 53. However, this basic approach is adequate for most use cases.

Take, for instance, date strings like '2024-W24' or '2024-w24'. In these cases, it's ambiguous whether '24' denotes a regular weekday or an ISO week number.

Consider the following practical scenario: Suppose we generate a string using the format 'YYYY-[W]WW'. Later, we need to verify if a given string adheres to this format. In such cases, we would typically employ customParseFormat, reusing the original format string. This is where support for 'WW' in ISO week notation becomes crucial. (It's worth noting that using 'ww' would yield consistent results in parsing scenarios, but 'WW' maintains format consistency.)

const fileDateFormat = "YYYY-[W]WW";

function buildFileName(date) {
   return dayjs(date).format(fileDateFormat);
}

function checkNoteName(fileName) {
  // here we reused the fileDateFormat
  const parsedDate = dayjs(fileName, fileDateFormat);
  return parsedDate && parsedDate.format(fileDateFormat) === fileName;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants