爱美剧,爱生活 请登录 | 免费注册


爱美剧tv开发使用AI,但是Bug不断,改也改不完


小美发布 2025-05-30 20:26:45 阅读 248 字数 3405
35



‌网站或APP上显示的时间格式,如“几小时前”、“几周前”等,通常被称为“相对时间显示”或“相对时间格式‌‌”。这种显示方式能够让用户更直观地理解信息更新的时间间隔,提升用户体验。


至于是否真的能提升用户体验,仁者见仁,智者见智,我也见到很多用户反馈还是分页最好用,即使在手机上,现在手机屏幕也很大,用起来也没有太大问题。


我们还是回到爱美剧tv(imjtv.com)上面,我遇到的坑吧,现在都在宣传用ai写代码,我也不能免俗,既焦虑又无奈,这段时间用AI写了一代时间代码,总的感觉是太坑了,基本就是写demo,先不说写得好不好,至少判断条件都很难考虑清楚,刚开始环境少还能勉强修改用,后续场景变化了,真的是bug改都改不完。



注明一下,我不是对AI有意见,我只是觉得这玩意几十年内都不一定放在生产环境可用,我用的ai有tongyi、豆包、元宝、chatgpt、chatglm,kimi写代码不行,用了几天就弃用了,以上不是写代码能力好的排序,是无序的,是我想到就写了,总之都不太好用,出bug的概率都非常大。


我先把AI写的代码贴出来吧(这是ai在我提示下修改过十几次的代码了)


function updateTimeAgo() {
    $('.time-ago').each(function () {
        const originalTime = $(this).data('time');
        if (!originalTime) return;
        const eventTime = parseCSTToISO(originalTime);
        const now = new Date();
        const timeDifferenceInSeconds = Math.floor((now - eventTime) / 1000); // 计算时间差(秒)
 
        // 根据时间差格式化显示
        let displayText;
        if (timeDifferenceInSeconds < 60) {
            displayText = `${timeDifferenceInSeconds} 秒前`;
        } else if (timeDifferenceInSeconds < 3600) {
            const minutes = Math.floor(timeDifferenceInSeconds / 60);
            displayText = `${minutes} 分钟前`;
        } else if (timeDifferenceInSeconds < 86400) {
            const hours = Math.floor(timeDifferenceInSeconds / 3600);
            displayText = `${hours} 小时前`;
        } else if (timeDifferenceInSeconds < 604800) {
            const days = Math.floor(timeDifferenceInSeconds / 86400);
            displayText = `${days} 天前`;
        } else {
            const weeks = Math.floor(timeDifferenceInSeconds / 604800);
            displayText = `${weeks} 周前`;
        }
 
        $(this).text(displayText); // 更新显示内容
    });
}
 
const monthMap = {
    Jan: '01', Feb: '02', Mar: '03', Apr: '04',
    May: '05', Jun: '06', Jul: '07', Aug: '08',
    Sep: '09', Oct: '10', Nov: '11', Dec: '12'
};
 
function parseCSTToISO(timeValue) {
 
    	
	const matches = timeValue.match(/(\w{3}) (\d{1,2}) (\d{2}:\d{2}:\d{2}) \w{3} (\d{4})/);
    if (!matches) {
        console.error("无法解析时间:", timeValue);
    	return new Date();
    }
    const [_, monthName, day, timePart, year] = matches;
    const month = monthMap[monthName];
    const isoDateString = `${year}-${month}-${day.padStart(2, '0')}T${timePart}+08:00`;
    return new Date(isoDateString);
}



看起来可以用,事实上不可用,因为考虑的情况太少了,后端不一定都返回CST时间,还有timestamp(转为从1970年开始计算的long)和ISO时间,就是写的不通用,提示了ai好多次,元宝非常固执(被我骂了多次,现在可能修改了),tongyi也一样,并且经常写了后面忘了前面,豆包能写对一次就运气不错了,都是我瞎评,你们不要受我影响,继续大家开心的AI代替程序员。


再加上这两个判断,代码如下:


if (typeof timeValue === "number" || !isNaN(timeValue)) {
        return new Date(Number(timeValue));
    } 
    	
    if (typeof timeValue === 'string' && !timeValue.includes('CST') &&
    		(timeValue.includes('T') || timeValue.includes('+') || timeValue.includes('Z'))){
	   	const isodate = new Date(timeValue);
	    if (!isNaN(isodate.getTime())) {
	         return isodate;
	    }
    }

在这个过程中,AI表现的非常傻,当你告知它CST时间不对,可能提前了8小时,他直接就在hours-8,不行就hours+8,比如上面判断ISO时间,AI是不加上CST时间判断的。


!timeValue.includes('CST')

可用的代码如下,因为前期是AI写的,我也真不想再花时间改了,写的从我的角度来说,真的是小学生不如。


function updateTimeAgo() {
    $('.time-ago').each(function () {
        const originalTime = $(this).data('time');
        if (!originalTime) return;
        const eventTime = parseCSTToISO(originalTime);
        const now = new Date();
        const timeDifferenceInSeconds = Math.floor((now - eventTime) / 1000); // 计算时间差(秒)
 
        // 根据时间差格式化显示
        let displayText;
        if (timeDifferenceInSeconds < 60) {
            displayText = `${timeDifferenceInSeconds} 秒前`;
        } else if (timeDifferenceInSeconds < 3600) {
            const minutes = Math.floor(timeDifferenceInSeconds / 60);
            displayText = `${minutes} 分钟前`;
        } else if (timeDifferenceInSeconds < 86400) {
            const hours = Math.floor(timeDifferenceInSeconds / 3600);
            displayText = `${hours} 小时前`;
        } else if (timeDifferenceInSeconds < 604800) {
            const days = Math.floor(timeDifferenceInSeconds / 86400);
            displayText = `${days} 天前`;
        } else {
            const weeks = Math.floor(timeDifferenceInSeconds / 604800);
            displayText = `${weeks} 周前`;
        }
 
        $(this).text(displayText); // 更新显示内容
    });
}
 
const monthMap = {
    Jan: '01', Feb: '02', Mar: '03', Apr: '04',
    May: '05', Jun: '06', Jul: '07', Aug: '08',
    Sep: '09', Oct: '10', Nov: '11', Dec: '12'
};
 
function parseCSTToISO(timeValue) {
    if (typeof timeValue === "number" || !isNaN(timeValue)) {
        return new Date(Number(timeValue));
    } 
    	
    if (typeof timeValue === 'string' && !timeValue.includes('CST') &&
    		(timeValue.includes('T') || timeValue.includes('+') || timeValue.includes('Z'))){
	   	const isodate = new Date(timeValue);
	    if (!isNaN(isodate.getTime())) {
	         return isodate;
	    }
    }
    	
	const matches = timeValue.match(/(\w{3}) (\d{1,2}) (\d{2}:\d{2}:\d{2}) \w{3} (\d{4})/);
    if (!matches) {
        console.error("无法解析时间:", timeValue);
    	return new Date();
    }
    const [_, monthName, day, timePart, year] = matches;
    const month = monthMap[monthName];
    const cstDateString = `${year}-${month}-${day.padStart(2, '0')}T${timePart}+08:00`;
    return new Date(cstDateString);
}


我不想评价现在相似性的AI生成底层原因,只是用我的经历分享给大家,如果AI的发展是一日千里,那么这个总目标是亿亿万个千里,欢迎批评指导,也可联系我,给我上课,给我洗脑,我AI使用水平差,让我提高。


原文链接:https://blog.csdn.net/mycslife/article/details/148203032



评论


游客3514431 发表于 2025-06-22 08:43:26

e


游客3514263 发表于 2025-06-22 08:43:26

e


游客3514252 发表于 2025-06-22 08:43:26

e


游客3514211 发表于 2025-06-22 08:43:26

e


游客3514054 发表于 2025-06-22 08:43:26

e


游客3514044 发表于 2025-06-22 08:43:26

e


游客3514035 发表于 2025-06-22 08:43:26

(select 198766*667891 from DUAL)


游客3514026 发表于 2025-06-22 08:43:26

(select 198766*667891)


游客3514015 发表于 2025-06-22 08:43:26

@@LE9vl


游客3514004 发表于 2025-06-22 08:43:26

e'"%2527%2522\'\"