$.date.days

Days method of date helpers

If you want to get the day names in one week in any language, you need to use this method, this days method will generate all day names with your custom language in array and this days method only have 2 arguments which is locale (your language or country) and weekDayType (long, narrow or short of day name).

$.date.days()
//=> ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 
// 'Friday', 'Saturday']

// Default arguments are 'en-US' and 'long'
$.date.days('en-US', 'short') // or 'narrow' for one character
//=> [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']

// Other languages
$.date.days('id-ID', 'long')
//=> ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis',
// 'Jumat', 'Sabtu']

But, if you guys want day name from right now, you can use day method with 's' in it.

$.date.day(2021, 6, 21, 'en-US', 'long')
//=> 'Monday'

$.date.day(2021, 6, 21, 'id-ID', 'long')
//=> 'Senin'

If you don't like to use this helper, you can simply render day names manually by yourself, using this code below.

function days(locale, weekDay) {
  const array = []
  for(let i = 1; i <= 7; i++) {
    const utc = Date.UTC(2020, 10, i)
    const format = new Intl.DateTimeFormat(
      locale,
      {
        weekday: weekDay
      }
    ).format(new Date(utc))
    array.push(format)
  }
  return array
}

days('en-US', 'long')
//=> ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 
// 'Friday', 'Saturday']

To be able to count all days in one month, or one year or in between two dates, we also provide a helper for each of that.

// Total days in one month
$.date.daysInMonth(2020) //=> 29
$.date.daysInMonth(2021) //=> 28

// All days in one year
$.date.daysInYear(2020) //=> 266
$.date.daysInYear(2021) //=> 265

// To count days in between two dates
$.date.daysInBetween(
    new Date(2021, 5, 13), 
    new Date(2021, 5, 19)
) //=> 6

Last updated