question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generating `daysOfTheWeek` array with only first character

See original GitHub issue

https://github.com/kylestetz/CLNDR/blob/555cf44c19dbf719c559a3ae86314d3eae0c5a25/src/clndr.js#L348

When this plugin generates daysOfTheWeek array from momentjs localized dd format, it only considers the first character, even when it formats it with the “min” version from momentjs.

In Catalan, for example, every day name begins with same letter d (dilluns, dimarts, dimecres, …), so I end up having a day names header full of D.

Would you consider respecting whatever comes from momentjs when formatting it with dd? Or at least, give an option to let us chose without the need to fill this array everytime we instantiate a new CLNDR?

Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kylestetzcommented, Jul 15, 2019

@aprat84 thanks for pointing this out, we definitely want to support more flexible day headers.

@mikegioia I like your idea! What if we take it a tad further and expose a function formatWeekdayHeader that exposes a moment object set to the correct weekday and allows you to return any string? That would allow you to run both .format('dd') or do some more complicated logic for a given locale (like we currently do with charAt). The default could be (m) => m.format('dd').charAt(0) or we could improve things by doing the en locale check that you suggested. I like this because it also opens up the possibility of e.g. doing completely custom headers by inspecting m.weekday() and pulling from your own array of strings.

$('.calendar').clndr({
  ...
  formatWeekdayHeader: (day) => day.format('dd'),
})

Thoughts? Would this work for you @aprat84?

0reactions
mikegioiacommented, Nov 27, 2019

@aprat84 @kylestetz This is now added to version 1.5.1, and updated in NPM!

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript array only first character displayed - Stack Overflow
So, to summarize... split() Splits a String object into an array of strings by separating the string into substrings.
Read more >
Use the map method on the daysOfWeek array, creating a ...
The "charAt" method will return just one single character. You could potentially call it 3 times and combine with concatenation. For creating a ......
Read more >
Documentation: 15: 8.15. Arrays - PostgreSQL
To illustrate the use of array types, we create this table: ... this query retrieves the first item on Bill's schedule for the...
Read more >
How to get the first three characters of a string using JavaScript
Create an array containing the days of the week. By using the index get the preferred day name. By using the slice method...
Read more >
How to create an array of type string and initialise it to the days ...
Let's just assume you were to code this problem in java. There are several ways you can initialize the array to the days...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found