Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

记录 DEV 路上踩过的坑 #159

Open
yanyue404 opened this issue Jul 28, 2020 · 0 comments
Open

记录 DEV 路上踩过的坑 #159

yanyue404 opened this issue Jul 28, 2020 · 0 comments

Comments

@yanyue404
Copy link
Owner

yanyue404 commented Jul 28, 2020

目录

1. IOS 设备无法正确解析 ISO 8601 时间格式

复现

new Date('2020-07-22T10:54:14.000+0000'); // 解析失败
new Date('2020/07/22 10:54:14'); // 格式化后正确解析

// 原因: 时间字符串中的 '-' 在部分 IOS 设备上无法兼容,需要替换为'/'的标准格式
const date = new Date(timeStr.replace(/-/g, '/'));

解决方案

const formatTimeByDateStr = (dateStr) => {
  let date = getDateFormISO8601(dateStr);
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  const hour = date.getHours();
  const minute = date.getMinutes();
  const second = date.getSeconds();

  return (
    [year, month, day].map(formatNumber).join('-') +
    ' ' +
    [hour, minute, second].map(formatNumber).join(':')
  );
};
const getDateFormISO8601 = (dateStr) => {
  // 修改 new Date(ISO 8601 时间,eg: 2020-07-22T10:54:14.000+0000)为 ios 支持的 2020/07/22 10:54:14
  const replace = (str) => {
    console.log(str);
    let date = str.slice(0, 10).replace(/-/g, '/');
    let time = str.slice(11, 19);
    let res = date + ' ' + time;
    return res;
  };
  let timeStr = replace(dateStr);
  let date = new Date(timeStr);
  // 修正时间偏移量 8 小时 2020/07/22 18:54:14
  date.setHours(date.getHours() + 8);
  return date;
};

2. Node Sass to Dart Sass

将 node-sass 转换为 dart-sass,解决 node-sass 安装困难症。

升级方式如下:

npm uninstall node-sass

npm install sass -S -D

参考

@yanyue404 yanyue404 added the Css label Jul 28, 2020
@yanyue404 yanyue404 changed the title DEV 路上踩过的坑 记录 DEV 路上踩过的坑 Jul 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant