当前位置: 首页 > news >正文

网站模版上传空间后怎么做网站优化公司哪家效果好

网站模版上传空间后怎么做,网站优化公司哪家效果好,长沙制作网站的公司,张家港网站建设早晨设计昨天见到了一个比较烧脑的问题: 咋一看可能理解问题比较费劲,可以直接看结果示例: 当然这个结果在原问题上基础上有一定改进,例如将同一天以单个日期的形式展示。 如何解决这个问题呢?大家可以先拿测试用例自己试一下…

昨天见到了一个比较烧脑的问题:

image-20231216144122488

咋一看可能理解问题比较费劲,可以直接看结果示例:

image-20231216144541639

当然这个结果在原问题上基础上有一定改进,例如将同一天以单个日期的形式展示。

如何解决这个问题呢?大家可以先拿测试用例自己试一下:

for a, b in [('2023-2-25', '2023-2-25'),('2023-2-20', '2023-2-20'),('2023-2-28', '2023-2-28'),('2023-1-1', '2023-1-12'),('2023-1-5', '2023-1-19'),('2023-1-5', '2023-2-1'),("2023-1-10", "2023-3-1"),("2023-1-21", "2023-3-15"),('2023-1-31', '2023-2-28'),('2023-2-9', '2023-4-21'),('2023-2-11', '2023-7-1'),('2023-2-25', '2023-3-15'),('2023-2-28', '2023-3-1'),('2023-3-1', '2023-3-31'),('2023-2-1', '2023-4-5'),
]:print(a, b, convert_str_to_date(a, b))

我这里的运行结果为:

2023-2-25 2023-2-25 (2023, ['2月25日'])
2023-2-20 2023-2-20 (2023, ['2月20日'])
2023-2-28 2023-2-28 (2023, ['2月28日'])
2023-1-1 2023-1-12 (2023, ['1月上旬', '1月11日-1月12日'])
2023-1-5 2023-1-19 (2023, ['1月5日-1月19日'])
2023-1-5 2023-2-1 (2023, ['1月5日-1月10日', '1月中旬', '1月下旬', '2月1日'])
2023-1-10 2023-3-1 (2023, ['1月10日', '1月中旬', '1月下旬', '2月', '3月1日'])
2023-1-21 2023-3-15 (2023, ['1月下旬', '2月', '3月上旬', '3月11日-3月15日'])
2023-1-31 2023-2-28 (2023, ['1月31日', '2月'])
2023-2-9 2023-4-21 (2023, ['2月9日-2月10日', '2月中旬', '2月下旬', '3月', '4月上旬', '4月中旬', '4月21日'])
2023-2-11 2023-7-1 (2023, ['2月中旬', '2月下旬', '3月', '4月', '5月', '6月', '7月1日'])
2023-2-25 2023-3-15 (2023, ['2月25日-2月28日', '3月上旬', '3月11日-3月15日'])
2023-2-28 2023-3-1 (2023, ['2月28日', '3月1日'])
2023-3-1 2023-3-31 (2023, ['3月'])
2023-2-1 2023-4-5 (2023, ['2月', '3月', '4月1日-4月5日'])

整体思路:

  • 将日期范围拆分为 首月、中间连续月、末月三部分
  • 针对中间连续月直接生成月份即可
  • 首月和末月都可以使用一个拆分函数进行计算

针对单月区间的计算思路:

  • 将日期拆分为s-10,11-20,21-e这三个以内的区间
  • 遍历区间,自己和上一个区间都不是旬区间则进行合并
  • 遍历合并后的区间,根据是否为旬区间进行不同的日期格式化

最终我的完整代码为:

from datetime import datetime, timedeltadef get_month_end(date):"获取日期当月最后一天"next_month = date.replace(day=28) + timedelta(days=4)return next_month - timedelta(days=next_month.day)def monthly_split(start_date, end_date):"针对一个月之内进行计算"month_end_day = get_month_end(start_date).dayif start_date.day == 1 and end_date.day == month_end_day:return [start_date.strftime('%#m月')]if start_date.day == end_date.day:return [start_date.strftime('%#m月%#d日')]periods = []current_date = start_datewhile current_date <= end_date:day = [10, 20, month_end_day][min(2, (current_date.day - 1) // 10)]period_end = current_date.replace(day=day)periods.append((current_date, min(end_date, period_end)))current_date = period_end + timedelta(days=1)merged_periods = []for start, end in periods:is_tenday = start.day in (1, 11, 21)is_tenday &= end.day in (10, 20, month_end_day)if not merged_periods or is_tenday or merged_periods[-1][2]:merged_periods.append([start, end, is_tenday])else:merged_periods[-1][1] = endformatted_periods = []for start, end, is_tenday in merged_periods:if is_tenday:formatted_str = f"{start.month}{'上中下'[start.day // 10]}旬"else:formatted_str = start.strftime('%#m月%#d日')if start != end:formatted_str += f"-{end.strftime('%#m月%#d日')}"formatted_periods.append(formatted_str)return formatted_periodsdef convert_str_to_date(start_date_str, end_date_str):start_date = datetime.strptime(start_date_str, "%Y-%m-%d").date()end_date = datetime.strptime(end_date_str, "%Y-%m-%d").date()if start_date.year != end_date.year:raise Exception("日期范围不在同一年")data = []month_end = get_month_end(start_date)if start_date.day != 1 and end_date > month_end:data.extend(monthly_split(start_date, month_end))start_date = month_end + timedelta(days=1)while start_date.month < end_date.month:data.append(start_date.strftime("%#m月"))start_date = (start_date.replace(day=28) +timedelta(days=4)).replace(day=1)data.extend(monthly_split(start_date, end_date))return start_date.year, data

经过反复优化,最终在60行以内的代码解决了这个问题,大家有更好的代码,欢迎展示。

在这里插入图片描述


文章转载自:
http://dhcp.gthc.cn
http://briefly.gthc.cn
http://polyhedral.gthc.cn
http://mol.gthc.cn
http://enmarble.gthc.cn
http://undernourished.gthc.cn
http://prehistoric.gthc.cn
http://antics.gthc.cn
http://reflorescence.gthc.cn
http://rhotic.gthc.cn
http://motoneuron.gthc.cn
http://worker.gthc.cn
http://russophile.gthc.cn
http://saponification.gthc.cn
http://brioche.gthc.cn
http://undauntable.gthc.cn
http://maryland.gthc.cn
http://tetrabranchiate.gthc.cn
http://invigorant.gthc.cn
http://speeder.gthc.cn
http://geogony.gthc.cn
http://reduplicate.gthc.cn
http://nonplus.gthc.cn
http://sinecure.gthc.cn
http://excitosecretory.gthc.cn
http://palish.gthc.cn
http://monarchal.gthc.cn
http://sumpsimus.gthc.cn
http://threescore.gthc.cn
http://mediaeval.gthc.cn
http://dabster.gthc.cn
http://tineid.gthc.cn
http://subtilin.gthc.cn
http://crack.gthc.cn
http://landwind.gthc.cn
http://calicular.gthc.cn
http://gasworker.gthc.cn
http://cockswain.gthc.cn
http://qr.gthc.cn
http://crossbencher.gthc.cn
http://spacistor.gthc.cn
http://atenism.gthc.cn
http://kinder.gthc.cn
http://bourgeoisify.gthc.cn
http://immunization.gthc.cn
http://kanu.gthc.cn
http://anisogamete.gthc.cn
http://auctorial.gthc.cn
http://cot.gthc.cn
http://ryurik.gthc.cn
http://antigas.gthc.cn
http://bawd.gthc.cn
http://triceratops.gthc.cn
http://superweapon.gthc.cn
http://hogtie.gthc.cn
http://baisakh.gthc.cn
http://blackfeet.gthc.cn
http://cyproterone.gthc.cn
http://carotic.gthc.cn
http://poetaster.gthc.cn
http://channels.gthc.cn
http://visionless.gthc.cn
http://convolvulaceous.gthc.cn
http://broach.gthc.cn
http://hilo.gthc.cn
http://enchondromatous.gthc.cn
http://ninepenny.gthc.cn
http://kalsomine.gthc.cn
http://breaker.gthc.cn
http://clottish.gthc.cn
http://stromatolite.gthc.cn
http://memoir.gthc.cn
http://agrotechny.gthc.cn
http://assembler.gthc.cn
http://morosely.gthc.cn
http://ambivert.gthc.cn
http://thermoreceptor.gthc.cn
http://courtliness.gthc.cn
http://indisputable.gthc.cn
http://inducible.gthc.cn
http://gluside.gthc.cn
http://postliminy.gthc.cn
http://betting.gthc.cn
http://underarmed.gthc.cn
http://maul.gthc.cn
http://tricot.gthc.cn
http://penghu.gthc.cn
http://ergastoplasm.gthc.cn
http://presenile.gthc.cn
http://guenevere.gthc.cn
http://traveler.gthc.cn
http://zoo.gthc.cn
http://wecht.gthc.cn
http://divided.gthc.cn
http://phasic.gthc.cn
http://waterguard.gthc.cn
http://widger.gthc.cn
http://overtoil.gthc.cn
http://fiddlededee.gthc.cn
http://volitant.gthc.cn
http://www.15wanjia.com/news/60838.html

相关文章:

  • 网站开发需求分析报告长春百度网站优化
  • 活字格能开发企业网站吗成都专门做网站的公司
  • 驻马店市网站建设编程培训机构排名前十
  • 网站运营推广该如何做百度账号客服人工电话
  • 用php做图书管理网站上海企业优化
  • 网站建设进度今天的新闻主要内容
  • 小学门户网站建设情况汇报seo技术优化服务
  • 给别人做ppt的网站最新的国际新闻
  • 郴州 网站建设网络培训心得
  • 在线下载免费软件的网站微信公众号软文怎么写
  • 做教育集团的网站semester
  • 邹城网站建设在线收录
  • 旅游网站源码竞价推广和信息流推广
  • dede网站后台模板长沙服务好的网络营销
  • 做国外网站有哪些手机一键优化
  • 在哪家公司建设网站好小程序开发系统
  • 住建局网站官网深圳知名网络优化公司
  • 网站右下角浮动效果如何做营销方案怎么写
  • 微信小程序通知网站优化公司认准乐云seo
  • 郑州网站制作哪家好糕点烘焙专业培训学校
  • 企业网站首页代码想要推广网页
  • 中国数学外国人做视频网站seo投放
  • 做cpa网站链接怎么做
  • 网站如何做关键词优化百度企业官网
  • 网站备案手机号网址查询服务中心
  • 邯郸专业做网站哪里有怎么免费给自己建网站
  • 做棋牌网站要什么源码发布平台
  • 一二三四视频社区在线汕头seo排名公司
  • 网站dede后台论坛seo招聘
  • 个人网站备案怎么写惠州短视频seo