[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $TypeError = require('es-errors/type');
|
---|
| 4 |
|
---|
| 5 | var weekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
---|
| 6 | var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
---|
| 7 |
|
---|
| 8 | var $isNaN = require('../helpers/isNaN');
|
---|
| 9 | var padTimeComponent = require('../helpers/padTimeComponent');
|
---|
| 10 |
|
---|
| 11 | var DateFromTime = require('./DateFromTime');
|
---|
| 12 | var MonthFromTime = require('./MonthFromTime');
|
---|
| 13 | var WeekDay = require('./WeekDay');
|
---|
| 14 | var YearFromTime = require('./YearFromTime');
|
---|
| 15 |
|
---|
| 16 | // https://262.ecma-international.org/9.0/#sec-datestring
|
---|
| 17 |
|
---|
| 18 | module.exports = function DateString(tv) {
|
---|
| 19 | if (typeof tv !== 'number' || $isNaN(tv)) {
|
---|
| 20 | throw new $TypeError('Assertion failed: `tv` must be a non-NaN Number');
|
---|
| 21 | }
|
---|
| 22 | var weekday = weekdays[WeekDay(tv)];
|
---|
| 23 | var month = months[MonthFromTime(tv)];
|
---|
| 24 | var day = padTimeComponent(DateFromTime(tv));
|
---|
| 25 | var year = padTimeComponent(YearFromTime(tv), 4);
|
---|
| 26 | return weekday + '\x20' + month + '\x20' + day + '\x20' + year;
|
---|
| 27 | };
|
---|