How to use the isValid function from date-fns

Find comprehensive JavaScript date-fns.isValid code examples handpicked from public code repositorys.

124
125
126
127
128
129
130
131
132
133
exports.isThisYearImpl = dateFns.isThisYear
exports.isThursdayImpl = dateFns.isThursday
exports.isTodayImpl = dateFns.isToday
exports.isTomorrowImpl = dateFns.isTomorrow
exports.isTuesdayImpl = dateFns.isTuesday
exports.isValidImpl = dateFns.isValid
exports.isWednesdayImpl = dateFns.isWednesday
exports.isWeekendImpl = dateFns.isWeekend
exports.isWithinRangeImpl = dateFns.isWithinRange
exports.isYesterdayImpl = dateFns.isYesterday
fork icon0
star icon2
watch icon1

+ 16 other calls in file

39
40
41
42
43
44
45
46
47
48
const blobStorageSasUri = getParam('blob-storage-sas-uri')
const blobStorageConnectionString = getParam('blob-storage-connection-string')
const blobStorageContainerName = getParam('blob-storage-container-name')
const allowSelfSignedCertificates = getParam('allow-self-signed-certificates')
const hasTokenIfNeeded = (iccIds.length || simIds.length) ? !!token : true
const areDatesValid = isValid(from) && isValid(to)
const isUsingBlobStorage = blobStorageSasUri || blobStorageConnectionString || blobStorageContainerName
const hasAllBlobStorageParams = (blobStorageSasUri || blobStorageConnectionString) && blobStorageContainerName
const isUsingS3 = s3Bucket || s3Region || awsAccessKeyId || awsSecretAccessKey
const hasAllS3Params = s3Bucket && s3Region && awsAccessKeyId && awsSecretAccessKey
fork icon1
star icon1
watch icon0

149
150
151
152
153
154
155
156
157
158
159
    return parseDate(value);
  }


  fromDB(value) {
    const cast = new Date(value);
    return dateFns.isValid(cast) ? dateFns.formatISO(cast, { representation: 'date' }) : null;
  }
}
class DatetimeField extends Field {
  toDB(value) {
fork icon0
star icon0
watch icon1

+ 140 other calls in file

190
191
192
193
194
195
196
197
198

if (date === undefined) {
  response.status(400);
  response.send("Invalid Due Date");
} else {
  const isDateValid = isValid(new Date(date));

  if (isDateValid) {
    const formattedDate = formatDate(date);
fork icon0
star icon0
watch icon1

+ 200 other calls in file

154
155
156
157
158
159
160
161
162
163
components: {
    PickerPopup: script$4,
},
emits: {
    'update:pageDate': (date) => dateFns.isValid(date),
    select: (date) => dateFns.isValid(date),
},
props: {
    selected: {
        type: Date,
fork icon0
star icon0
watch icon0

+ 89 other calls in file

34
35
36
37
38
39
40
41
42
43
44
45
46
};


const validateDate = (date) => {
  const regex = new RegExp('\\d{4}-\\d{2}-\\d{2}');
  const matched = regex.test(date);
  const isDataValid = isValid(parse(date, 'yyyy-MM-dd', new Date()));


  if (!matched || !isDataValid) return false;


  return date;
fork icon0
star icon0
watch icon0

11
12
13
14
15
16
17
18
19
20
 * @returns {boolean}
 */
const isValidDate = (date) => {
  try {
    return (
      dateFns.isValid(new Date(date)) &&
      !checkDateLaterThanNow(new Date(date)) &&
      !Number.isNaN(Date.parse(date))
    );
  } catch {
fork icon0
star icon0
watch icon0

Other functions in date-fns

Sorted by popularity

function icon

date-fns.format is the most popular function in date-fns (3838 examples)