How to use the date function from joi

Find comprehensive JavaScript joi.date code examples handpicked from public code repositorys.

125
126
127
128
129
130
131
132
133
134
    updatedAtParamName = self.updatedAt;
  }
}

if(self.createdAt !== false) {
  valids[createdAtParamName] = Joi.date();
}

if(self.updatedAt !== false) {
  valids[updatedAtParamName] = Joi.date();
fork icon87
star icon292
watch icon8

+ 7 other calls in file

3
4
5
6
7
8
9
10
11
12
const Joi = require('joi');

const extensions = [
    { type: 'int64', base: Joi.string().regex(/^\d+$/) },
    { type: 'byte', base: Joi.string().base64() },
    { type: 'date-time', base: Joi.date().iso() },
    {
        type: 'file',
        base: Joi.object({
            value: Joi.binary().required(true),
fork icon75
star icon207
watch icon21

8
9
10
11
12
13
14
15
16
17
    archiveInfo: joi.object().required(),
    requestId: joi.string().required(),

    originalMessage: joi.object(),
    reason: joi.optional(),
    date: joi.date().optional(),
    eTag: joi.string().optional(),
}).unknown(true);

class ColdStorageStatusQueueEntry {
fork icon18
star icon51
watch icon60

942
943
944
945
946
947
948
949
950
951
projectId: Joi.number().integer().positive(),
forumId: Joi.number().integer(),
legacyId: Joi.number().integer().positive(),
status: Joi.string().valid(_.values(constants.challengeStatuses)),
group: Joi.string(),
startDateStart: Joi.date(),
startDateEnd: Joi.date(),
endDateStart: Joi.date(),
endDateEnd: Joi.date(),
currentPhaseName: Joi.string(),
fork icon44
star icon17
watch icon25

+ 79 other calls in file

23
24
25
26
27
28
29
30
31
32
    },
}));

const BodyDto = Joi.object({
    timeO2Start: Joi.date().optional(),
    timeTrgStart: Joi.date().optional(),
    environmentId: Joi.string(),
    runType: Joi.string(),
    nDetectors: Joi.number(),
    nFlps: Joi.number(),
fork icon13
star icon14
watch icon7

+ 3 other calls in file

56
57
58
59
60
61
62
63
64

// Given a Joi schema:
const Article = object({
  title: string(),
  body: string(),
  published_at: date()
}).meta({
  args: { id: number().required() }
})
fork icon237
star icon0
watch icon1

5
6
7
8
9
10
11
12
13
14
const GitHub = require('../../models/github')
const User = require('../../models/user')
const Contribution = require('../../models/contribution')

const schema = joi.object({
  date: joi.date().raw().required(),
  repository: joi.object({
    id: joi.number().integer().required(),
    full_name: joi.string().required()
  }).unknown().required()
fork icon167
star icon0
watch icon2

34
35
36
37
38
39
40
41
42
43
  capture(idError);
  return res.status(400).send({ ok: false, code: ERRORS.INVALID_PARAMS });
}

const bodySchema = Joi.object().keys({
  date: Joi.date().allow(""),
});

const result = bodySchema.validate(req.body, { stripUnknown: true });
const {
fork icon4
star icon9
watch icon0

+ 5 other calls in file

500
501
502
503
504
505
506
507
508
509
  young.set({ latestCNIFileExpirationDate: value.date, CNIFileNotValidOnStart });
}

if (type === "correction") {
  const fileSchema = {
    latestCNIFileExpirationDate: Joi.date().required(),
    latestCNIFileCategory: Joi.string().trim().required(),
  };
  const { error, value } = Joi.object(fileSchema).validate(req.body, { stripUnknown: true });
  if (error) {
fork icon4
star icon8
watch icon4

+ 4 other calls in file

61
62
63
64
65
66
67
68
69
70
  .trim()
  .valid(...PHONE_ZONES_NAMES_ARR)
  .default(PHONE_ZONES_NAMES.FRANCE),
latestCNIFileExpirationDate: Joi.date(),
latestCNIFileCategory: Joi.string().trim(),
birthdateAt: Joi.date(),
birthCity: Joi.string().trim(),
birthCityZip: Joi.string().trim(),
birthCountry: Joi.string().trim(),
address: Joi.string().trim(),
fork icon4
star icon8
watch icon4

+ 9 other calls in file

10
11
12
13
14
15
16
17
18
19
amount: Joi.number().min(0).required().messages({
  'number.base': `{{#label}} should be a type of number`,
  'number.min': `{{#label}} cannot be negative and must be greater than 0`,
  'any.required': `{{#label}} is a required field`,
}),
date: Joi.date().iso().required().messages({
  'date.base': `{{#label}} should be a type of date`,
  'any.required': `{{#label}} is a required field`,
}),
comment: Joi.string()
fork icon2
star icon2
watch icon0

70
71
72
73
74
75
76
77
78
79

row.conforms = schema._tests.slice();
if (schema._flags.format) {
  row.conforms.push({
    name: 'format',
    arg: schema._flags.format === joi.date().iso()._flags.format ? 'iso' : schema._flags.format,
  });
}
if (schema._flags.insensitive) {
  row.conforms.push({
fork icon2
star icon1
watch icon0

+ 4 other calls in file

2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
                allowRelative: false
            })
            .example('https://myservice.com/imap/webhooks')
            .description('Account-specific webhook URL'),
        proxy: settingsSchema.proxyUrl,
        syncTime: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('Last sync time'),
        lastError: lastErrorSchema.allow(null)
    }).label('AccountResponseItem')
)
.label('AccountEntries')
fork icon113
star icon0
watch icon16

+ 19 other calls in file

1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
  })).min(1).required()
})),
tags: Joi.array().items(Joi.string()), // tag names
projectId: Joi.number().integer().positive(),
legacyId: Joi.number().integer().positive(),
startDate: Joi.date(),
status: Joi.string().valid(_.values(constants.challengeStatuses)),
groups: Joi.array().items(Joi.optionalId()).unique(),
// gitRepoURLs: Joi.array().items(Joi.string().uri()),
terms: Joi.array().items(Joi.object().keys({
fork icon44
star icon17
watch icon25

+ 22 other calls in file

42
43
44
45
46
47
48
49
50
51
router.post("/", passport.authenticate("referent", { session: false, failWithError: true }), async (req, res) => {
  try {
    const { error, value } = Joi.object({
      cohort: Joi.string().required(),
      busId: Joi.string().required(),
      departuredDate: Joi.date().required(),
      returnDate: Joi.date().required(),
      youngCapacity: Joi.number().required(),
      totalCapacity: Joi.number().required(),
      followerCapacity: Joi.number().required(),
fork icon4
star icon8
watch icon3

+ 3 other calls in file

59
60
61
62
63
64
65
66
67
68
    old_password: Joi.string(),
    new_password: Joi.string().min(6).max(30),
    cnfNew_password: Joi.string(),
    phone: Joi.string().length(10),
    degree: Joi.string(),
    birth: Joi.date(),
    gender: Joi.string(),
  });
  return schema.validate(doctor);
};
fork icon2
star icon0
watch icon1

+ 9 other calls in file

77
78
79
80
81
82
83
84
85
  //resume:Joi.string().required(),
  //profileImage: Joi.string().required(),
  gitLink: Joi.string().required(),
  userDetailsID: Joi.string().required(),
  gender: Joi.string().required(),
  doB: Joi.date().required(),
  phone: Joi.string().required(),
  profileLink: Joi.string().required(),
});
fork icon1
star icon0
watch icon0

34
35
36
37
38
39
40
41
42
43
const schema = Joi.object({
  prenom: Joi.string().error(new Error('Le nom est invalide')),
  nom: Joi.string().error(new Error('Le nom est invalide')),
  telephone: Joi.string().required().max(10).error(new Error('Le format du téléphone est invalide, il doit contenir 10 chiffres ')),
  // eslint-disable-next-line max-len
  dateDisponibilite: Joi.date().error(new Error('La date est invalide, veuillez choisir une date supérieur ou égale à la date du jour')),
  email: Joi.string().email().error(new Error('Le format de l\'email est invalide')),
}).validate(body);

if (schema.error) {
fork icon0
star icon1
watch icon2

+ 5 other calls in file

62
63
64
65
66
67
68
69
70
71
dob: {
  type: Date,
  required: true,
  validate: {
    validator: function(value) {
      const schema = Joi.date().required();
      const { error } = schema.validate(value);
      return error ? false : true;
    },
    message: props => `${props.value} is not a valid date format!`
fork icon0
star icon1
watch icon1

+ 4 other calls in file

96
97
98
99
100
101
102
103
104
105
function validate(req) {
  const schema = Joi.object({
    ResID: Joi.string().required(),
    PhaseData : Joi.string().required(),
    AdmissionID: Joi.string().max(30),
    GuestInDate: Joi.date(),
    TreatmentCenterListID: Joi.string().max(30).optional().allow(""),
    WasHomeless: Joi.boolean(),
    WasJobless: Joi.boolean(),
    WasDomesticallyAbused: Joi.boolean(),
fork icon1
star icon2
watch icon1

+ 14 other calls in file