or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

collection-validation.mdconfiguration.mddate-time.mdenvironment-detection.mdindex.mdnumeric-operations.mdpattern-matching.mdpresence-checking.mdstring-checking.mdtype-checking.md
tile.json

date-time.mddocs/

0

# Date and Time

1

2

Comprehensive date validation including relative time checks, specific date matching, and time range validation.

3

4

## Capabilities

5

6

### Relative Time Checks

7

8

#### Today Check

9

10

Checks if the given date represents today.

11

12

```javascript { .api }

13

/**

14

* Checks if the given date object indicates today

15

* @param date - Date object to check

16

* @returns True if date is today

17

* Interfaces: not, all, any

18

*/

19

function today(date: Date): boolean;

20

```

21

22

**Usage Example:**

23

24

```javascript

25

const today = new Date();

26

is.today(today); // true

27

28

const yesterday = new Date(new Date().setDate(new Date().getDate() - 1));

29

is.today(yesterday); // false

30

is.not.today(yesterday); // true

31

is.all.today(today, today); // true

32

is.any.today(today, yesterday); // true

33

```

34

35

#### Yesterday Check

36

37

Checks if the given date represents yesterday.

38

39

```javascript { .api }

40

/**

41

* Checks if the given date object indicates yesterday

42

* @param date - Date object to check

43

* @returns True if date is yesterday

44

* Interfaces: not, all, any

45

*/

46

function yesterday(date: Date): boolean;

47

```

48

49

**Usage Example:**

50

51

```javascript

52

const today = new Date();

53

const yesterday = new Date(new Date().setDate(new Date().getDate() - 1));

54

55

is.yesterday(yesterday); // true

56

is.yesterday(today); // false

57

is.not.yesterday(today); // true

58

```

59

60

#### Tomorrow Check

61

62

Checks if the given date represents tomorrow.

63

64

```javascript { .api }

65

/**

66

* Checks if the given date object indicates tomorrow

67

* @param date - Date object to check

68

* @returns True if date is tomorrow

69

* Interfaces: not, all, any

70

*/

71

function tomorrow(date: Date): boolean;

72

```

73

74

**Usage Example:**

75

76

```javascript

77

const today = new Date();

78

const tomorrow = new Date(new Date().setDate(new Date().getDate() + 1));

79

80

is.tomorrow(tomorrow); // true

81

is.tomorrow(today); // false

82

is.not.tomorrow(today); // true

83

```

84

85

#### Past and Future Checks

86

87

Checks if the given date is in the past or future.

88

89

```javascript { .api }

90

/**

91

* Checks if the given date object indicates past

92

* @param date - Date object to check

93

* @returns True if date is in the past

94

* Interfaces: not, all, any

95

*/

96

function past(date: Date): boolean;

97

98

/**

99

* Checks if the given date object indicates future

100

* @param date - Date object to check

101

* @returns True if date is in the future

102

* Interfaces: not, all, any

103

*/

104

function future(date: Date): boolean;

105

```

106

107

**Usage Example:**

108

109

```javascript

110

const yesterday = new Date(new Date().setDate(new Date().getDate() - 1));

111

const tomorrow = new Date(new Date().setDate(new Date().getDate() + 1));

112

113

is.past(yesterday); // true

114

is.future(tomorrow); // true

115

is.not.past(tomorrow); // true

116

is.not.future(yesterday); // true

117

```

118

119

### Specific Date Matching

120

121

#### Day Check

122

123

Checks if the given date matches a specific day of the week.

124

125

```javascript { .api }

126

/**

127

* Checks if the given date objects' day equals given dayString parameter

128

* @param date - Date object to check

129

* @param day - Day name (lowercase: 'monday', 'tuesday', etc.)

130

* @returns True if date falls on the specified day

131

* Interfaces: not

132

*/

133

function day(date: Date, day: string): boolean;

134

```

135

136

**Usage Example:**

137

138

```javascript

139

const mondayObj = new Date('01/26/2015');

140

is.day(mondayObj, 'monday'); // true

141

is.day(mondayObj, 'tuesday'); // false

142

is.not.day(mondayObj, 'tuesday'); // true

143

```

144

145

#### Month Check

146

147

Checks if the given date matches a specific month.

148

149

```javascript { .api }

150

/**

151

* Checks if the given date objects' month equals given monthString parameter

152

* @param date - Date object to check

153

* @param month - Month name (lowercase: 'january', 'february', etc.)

154

* @returns True if date falls in the specified month

155

* Interfaces: not

156

*/

157

function month(date: Date, month: string): boolean;

158

```

159

160

**Usage Example:**

161

162

```javascript

163

const januaryObj = new Date('01/26/2015');

164

is.month(januaryObj, 'january'); // true

165

is.month(januaryObj, 'february'); // false

166

is.not.month(januaryObj, 'february'); // true

167

```

168

169

#### Year Check

170

171

Checks if the given date matches a specific year.

172

173

```javascript { .api }

174

/**

175

* Checks if the given date objects' year equals given yearNumber parameter

176

* @param date - Date object to check

177

* @param year - Year number

178

* @returns True if date falls in the specified year

179

* Interfaces: not

180

*/

181

function year(date: Date, year: number): boolean;

182

```

183

184

**Usage Example:**

185

186

```javascript

187

const year2015 = new Date('01/26/2015');

188

is.year(year2015, 2015); // true

189

is.year(year2015, 2016); // false

190

is.not.year(year2015, 2016); // true

191

```

192

193

### Time Range Validation

194

195

#### Date Range Check

196

197

Checks if a date falls within a specified range.

198

199

```javascript { .api }

200

/**

201

* Checks if date is within given range

202

* @param date - Date to check

203

* @param start - Start date of range

204

* @param end - End date of range

205

* @returns True if date is between start and end dates

206

* Interfaces: not

207

*/

208

function inDateRange(date: Date, start: Date, end: Date): boolean;

209

```

210

211

**Usage Example:**

212

213

```javascript

214

const saturday = new Date('01/24/2015');

215

const sunday = new Date('01/25/2015');

216

const monday = new Date('01/26/2015');

217

218

is.inDateRange(sunday, saturday, monday); // true

219

is.inDateRange(saturday, sunday, monday); // false

220

is.not.inDateRange(saturday, sunday, monday); // true

221

```

222

223

#### Relative Range Checks

224

225

Checks if dates fall within relative time periods.

226

227

```javascript { .api }

228

/**

229

* Checks if the given date is between now and 7 days ago

230

* @param date - Date to check

231

* @returns True if date is in last week

232

* Interfaces: not, all, any

233

*/

234

function inLastWeek(date: Date): boolean;

235

236

/**

237

* Checks if the given date is between now and a month ago

238

* @param date - Date to check

239

* @returns True if date is in last month

240

* Interfaces: not, all, any

241

*/

242

function inLastMonth(date: Date): boolean;

243

244

/**

245

* Checks if the given date is between now and a year ago

246

* @param date - Date to check

247

* @returns True if date is in last year

248

* Interfaces: not, all, any

249

*/

250

function inLastYear(date: Date): boolean;

251

252

/**

253

* Checks if the given date is between now and 7 days later

254

* @param date - Date to check

255

* @returns True if date is in next week

256

* Interfaces: not, all, any

257

*/

258

function inNextWeek(date: Date): boolean;

259

260

/**

261

* Checks if the given date is between now and a month later

262

* @param date - Date to check

263

* @returns True if date is in next month

264

* Interfaces: not, all, any

265

*/

266

function inNextMonth(date: Date): boolean;

267

268

/**

269

* Checks if the given date is between now and a year later

270

* @param date - Date to check

271

* @returns True if date is in next year

272

* Interfaces: not, all, any

273

*/

274

function inNextYear(date: Date): boolean;

275

```

276

277

### Weekend and Weekday Checks

278

279

Checks if dates fall on weekends or weekdays.

280

281

```javascript { .api }

282

/**

283

* Checks if the given date objects' day is weekend

284

* @param date - Date to check

285

* @returns True if date is Saturday or Sunday

286

* Interfaces: not, all, any

287

*/

288

function weekend(date: Date): boolean;

289

290

/**

291

* Checks if the given date objects' day is weekday

292

* @param date - Date to check

293

* @returns True if date is Monday through Friday

294

* Interfaces: not, all, any

295

*/

296

function weekday(date: Date): boolean;

297

```

298

299

**Usage Example:**

300

301

```javascript

302

const monday = new Date('01/26/2015');

303

const sunday = new Date('01/25/2015');

304

305

is.weekend(sunday); // true

306

is.weekday(monday); // true

307

is.not.weekend(monday); // true

308

is.not.weekday(sunday); // true

309

```

310

311

### Special Date Checks

312

313

#### Leap Year Check

314

315

Checks if the given year is a leap year.

316

317

```javascript { .api }

318

/**

319

* Checks if the given year number is a leap year

320

* @param year - Year number to check

321

* @returns True if year is a leap year

322

* Interfaces: not, all, any

323

*/

324

function leapYear(year: number): boolean;

325

```

326

327

**Usage Example:**

328

329

```javascript

330

is.leapYear(2016); // true

331

is.leapYear(2015); // false

332

is.not.leapYear(2015); // true

333

is.all.leapYear(2016, 2020); // true

334

is.any.leapYear(2015, 2016); // true

335

```

336

337

#### Quarter Check

338

339

Checks if the given date falls in a specific quarter.

340

341

```javascript { .api }

342

/**

343

* Checks if the given date is in the parameter quarter

344

* @param date - Date to check

345

* @param quarter - Quarter number (1-4)

346

* @returns True if date falls in specified quarter

347

* Interfaces: not

348

*/

349

function quarterOfYear(date: Date, quarter: number): boolean;

350

```

351

352

**Usage Example:**

353

354

```javascript

355

const firstQuarter = new Date('01/26/2015');

356

const secondQuarter = new Date('05/26/2015');

357

358

is.quarterOfYear(firstQuarter, 1); // true

359

is.quarterOfYear(secondQuarter, 1); // false

360

is.not.quarterOfYear(secondQuarter, 1); // true

361

```

362

363

#### Daylight Saving Time Check

364

365

Checks if the given date is in daylight saving time.

366

367

```javascript { .api }

368

/**

369

* Checks if the given date is in daylight saving time

370

* @param date - Date to check

371

* @returns True if date is in daylight saving time

372

* Interfaces: not, all, any

373

*/

374

function dayLightSavingTime(date: Date): boolean;

375

```

376

377

**Usage Example:**

378

379

```javascript

380

// For Turkey Time Zone

381

const january1 = new Date('01/01/2015');

382

const june1 = new Date('06/01/2015');

383

384

is.dayLightSavingTime(june1); // true

385

is.dayLightSavingTime(january1); // false

386

is.not.dayLightSavingTime(january1); // true

387

```