MCPcopy Create free account
hub / github.com/XIU2/UserScript / parseDay

Function parseDay

Lanzou-Enhanced.user.js:787–818  ·  view source on GitHub ↗
(time)

Source from the content-addressed store, hash-verified

785 // 转换时间格式
786 function parseTime(now, text) {
787 function parseDay(time) {
788 const days = [
789 {
790 name: '前天',
791 offset: -2,
792 },
793 {
794 name: '昨天',
795 offset: -1,
796 }
797 ];
798 const date = new Date(now.getTime());
799 let index = -1;
800 for (let i = 0; i < days.length; i++) {
801 if (time.indexOf(days[i].name) > -1) {
802 index = i;
803 break;
804 }
805 }
806 if (index === -1) return new Date(now.getTime());
807 const hourAndMinute = text.replace(days[index].name, '').split(':');
808 const hour = parseInt(hourAndMinute[0]);
809 const minute = parseInt(hourAndMinute[1]);
810 date.setDate(date.getDate() + days[index].offset);
811 date.setHours(hour);
812 date.setMinutes(minute);
813 // 蓝奏云显示比较奇怪,超过24小时,未满48小时,都是昨天,并不以每天0点作为分界
814 if (hour * 60 + minute > now.getHours() * 60 + now.getMinutes()) {
815 date.setDate(date.getDate() - 1);
816 }
817 return date;
818 }
819 if (text.indexOf('秒前') > -1) {
820 return now.getTime() - parseInt(text.replace('秒前', '')) * 1000;
821 } else if (text.indexOf('分钟前') > -1) {

Callers 1

parseTimeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected