Skip to content

Instantly share code, notes, and snippets.

@cncuckoo
Created December 17, 2018 09:43
Show Gist options
  • Save cncuckoo/7f5aa7f6a04004948610071f4b2e2476 to your computer and use it in GitHub Desktop.
Save cncuckoo/7f5aa7f6a04004948610071f4b2e2476 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/bucijozoka
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
#result .date {
font-family: monospace;
font-size: 1.3rem;
}
#result ul {
padding-left: 1.5rem;
}
</style>
</head>
<body>
<h3>W3C工作组当前发稿周期</h3>
<div id="result"></div>
<h5 id="today"></div>
<script id="jsbin-javascript">
// const epoch = 15371136e5
// 因冯通退出,2018-11-07将起始“纪元”重置为Date.parse('2018-10-17')
const epoch = Date.parse('2018-11-14')
const pofday = 864e5
const writers2018 = ['何文力', '刘宇晨', '黄小璐', '李松峰', '刘博文', '刘观宇', '安佳', '高峰']
const writers2019 = ['何文力', '黄小璐', '李松峰', '刘博文', '刘观宇', '安佳', '高峰']
const writers = (new Date()).getFullYear() === 2018 ? writers2018 : writers2019
const today = getToday()
// 测试用:将以后任意一天作为“今天”
// const today = new Date('2019-1-1')
let length = window.location.search.split('?length=')[1]
length = length ? length : 2
// 查询几个周期
const result = getCurrentTurn(length)
const d = document.getElementById('result')
d.innerHTML = fmtResult(result)
const t = document.getElementById('today')
// t.innerHTML = genDate(today)
/*
* 自动根据当前日期,显示当前所在轮次所有人的发稿时间
*/
function getCurrentTurn(turns = 1) {
let time = findStartPoint()
const pubDays = []
while (pubDays.length < writers.length * turns) {
if ('13'.indexOf(new Date(time).getDay()) > -1)
pubDays.push(time)
time += pofday
}
const result = pubDays.map((d, i) => {
const index = i % writers.length
const writer = writers[index]
const date = genDate(d)
return [date, writer]
})
return result
}
function findStartPoint() {
let time = epoch
let i = 0
const turnStarts = []
// 最初轮的起点时间
while (time < today) {
// 如果是发稿日,则i++
if ('13'.indexOf(new Date(time).getDay()) > -1) {
i++
// 如果i为初始发稿日,则记录该发稿日
if (i === 1) turnStarts.push(time)
}
// 如果i等于作者数,则一轮结束,i重置
if (i === writers.length) i = 0
time += pofday
}
// 返回最接近今天的最后一个发稿日
return turnStarts.pop()
}
/*
* 生成器函数
*/
function* gen(turns, all) {
if (typeof turns !== 'number' && typeof all !== 'number') {
return '无效参数。调用示例:g = gen(1)或g = gen(2,\'all\')'
}
const pubDays = []
let time = epoch
while (pubDays.length < turns * writers.length) {
if ('13'.indexOf(new Date(time).getDay()) > -1)
pubDays.push(time)
time += pofday
}
const result = pubDays.map((d, i) => {
const index = i % writers.length
const writer = writers[index]
const date = genDate(d)
return [date, writer]
})
// 如果不是查看全部轮次,则仅返回第turns轮的结果
if (all !== 'all') {
const startIndex = (turns - 1) * writers.length
const currentIteration = result.splice(startIndex, writers.length)
yield currentIteration
return
}
// 如果是查看全部轮次,则依次显示全部轮次
while (turns > 0) {
const startIndex = (turns - 1) * writers.length
const currentIteration = result.splice(startIndex, writers.length)
yield currentIteration
turns--
}
}
function getToday() {
const temp = new Date()
return new Date(temp.getFullYear() + '-' + (temp.getMonth() + 1) + '-' + (temp.getDate()+2) ).valueOf()
}
function genDate(d) {
const temp = new Date(d)
return temp.getFullYear() + '-' + padding((temp.getMonth() + 1)) + '-' + padding(temp.getDate())
}
function padding(v) {
v = String(v)
return v.length === 1 ? '0' + v : v
}
function fmtResult(ret) {
const lis = ret.map(item => {
return `<li><span class="date">${item[0]}</span> ${item[1]}</li>`
}).join('')
return `<ul>${lis}</ul>`
}
// const d = document.getElementById('result')
// const g = gen(2,'all')
// const t1 = g.next().value
// const t2 = g.next().value
// const t3 = g.next().value
// d.innerHTML = fmtResult(t1)
</script>
<script id="jsbin-source-css" type="text/css">#result .date {
font-family: monospace;
font-size: 1.3rem;
}
#result ul {
padding-left: 1.5rem;
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">// const epoch = 15371136e5
// 因冯通退出,2018-11-07将起始“纪元”重置为Date.parse('2018-10-17')
const epoch = Date.parse('2018-11-14')
const pofday = 864e5
const writers2018 = ['何文力', '刘宇晨', '黄小璐', '李松峰', '刘博文', '刘观宇', '安佳', '高峰']
const writers2019 = ['何文力', '黄小璐', '李松峰', '刘博文', '刘观宇', '安佳', '高峰']
const writers = (new Date()).getFullYear() === 2018 ? writers2018 : writers2019
const today = getToday()
// 测试用:将以后任意一天作为“今天”
// const today = new Date('2019-1-1')
let length = window.location.search.split('?length=')[1]
length = length ? length : 2
// 查询几个周期
const result = getCurrentTurn(length)
const d = document.getElementById('result')
d.innerHTML = fmtResult(result)
const t = document.getElementById('today')
// t.innerHTML = genDate(today)
/*
* 自动根据当前日期,显示当前所在轮次所有人的发稿时间
*/
function getCurrentTurn(turns = 1) {
let time = findStartPoint()
const pubDays = []
while (pubDays.length < writers.length * turns) {
if ('13'.indexOf(new Date(time).getDay()) > -1)
pubDays.push(time)
time += pofday
}
const result = pubDays.map((d, i) => {
const index = i % writers.length
const writer = writers[index]
const date = genDate(d)
return [date, writer]
})
return result
}
function findStartPoint() {
let time = epoch
let i = 0
const turnStarts = []
// 最初轮的起点时间
while (time < today) {
// 如果是发稿日,则i++
if ('13'.indexOf(new Date(time).getDay()) > -1) {
i++
// 如果i为初始发稿日,则记录该发稿日
if (i === 1) turnStarts.push(time)
}
// 如果i等于作者数,则一轮结束,i重置
if (i === writers.length) i = 0
time += pofday
}
// 返回最接近今天的最后一个发稿日
return turnStarts.pop()
}
/*
* 生成器函数
*/
function* gen(turns, all) {
if (typeof turns !== 'number' && typeof all !== 'number') {
return '无效参数。调用示例:g = gen(1)或g = gen(2,\'all\')'
}
const pubDays = []
let time = epoch
while (pubDays.length < turns * writers.length) {
if ('13'.indexOf(new Date(time).getDay()) > -1)
pubDays.push(time)
time += pofday
}
const result = pubDays.map((d, i) => {
const index = i % writers.length
const writer = writers[index]
const date = genDate(d)
return [date, writer]
})
// 如果不是查看全部轮次,则仅返回第turns轮的结果
if (all !== 'all') {
const startIndex = (turns - 1) * writers.length
const currentIteration = result.splice(startIndex, writers.length)
yield currentIteration
return
}
// 如果是查看全部轮次,则依次显示全部轮次
while (turns > 0) {
const startIndex = (turns - 1) * writers.length
const currentIteration = result.splice(startIndex, writers.length)
yield currentIteration
turns--
}
}
function getToday() {
const temp = new Date()
return new Date(temp.getFullYear() + '-' + (temp.getMonth() + 1) + '-' + (temp.getDate()+2) ).valueOf()
}
function genDate(d) {
const temp = new Date(d)
return temp.getFullYear() + '-' + padding((temp.getMonth() + 1)) + '-' + padding(temp.getDate())
}
function padding(v) {
v = String(v)
return v.length === 1 ? '0' + v : v
}
function fmtResult(ret) {
const lis = ret.map(item => {
return `<li><span class="date">${item[0]}</span> ${item[1]}</li>`
}).join('')
return `<ul>${lis}</ul>`
}
// const d = document.getElementById('result')
// const g = gen(2,'all')
// const t1 = g.next().value
// const t2 = g.next().value
// const t3 = g.next().value
// d.innerHTML = fmtResult(t1)
</script></body>
</html>
#result .date {
font-family: monospace;
font-size: 1.3rem;
}
#result ul {
padding-left: 1.5rem;
}
// const epoch = 15371136e5
// 因冯通退出,2018-11-07将起始“纪元”重置为Date.parse('2018-10-17')
const epoch = Date.parse('2018-11-14')
const pofday = 864e5
const writers2018 = ['何文力', '刘宇晨', '黄小璐', '李松峰', '刘博文', '刘观宇', '安佳', '高峰']
const writers2019 = ['何文力', '黄小璐', '李松峰', '刘博文', '刘观宇', '安佳', '高峰']
const writers = (new Date()).getFullYear() === 2018 ? writers2018 : writers2019
const today = getToday()
// 测试用:将以后任意一天作为“今天”
// const today = new Date('2019-1-1')
let length = window.location.search.split('?length=')[1]
length = length ? length : 2
// 查询几个周期
const result = getCurrentTurn(length)
const d = document.getElementById('result')
d.innerHTML = fmtResult(result)
const t = document.getElementById('today')
// t.innerHTML = genDate(today)
/*
* 自动根据当前日期,显示当前所在轮次所有人的发稿时间
*/
function getCurrentTurn(turns = 1) {
let time = findStartPoint()
const pubDays = []
while (pubDays.length < writers.length * turns) {
if ('13'.indexOf(new Date(time).getDay()) > -1)
pubDays.push(time)
time += pofday
}
const result = pubDays.map((d, i) => {
const index = i % writers.length
const writer = writers[index]
const date = genDate(d)
return [date, writer]
})
return result
}
function findStartPoint() {
let time = epoch
let i = 0
const turnStarts = []
// 最初轮的起点时间
while (time < today) {
// 如果是发稿日,则i++
if ('13'.indexOf(new Date(time).getDay()) > -1) {
i++
// 如果i为初始发稿日,则记录该发稿日
if (i === 1) turnStarts.push(time)
}
// 如果i等于作者数,则一轮结束,i重置
if (i === writers.length) i = 0
time += pofday
}
// 返回最接近今天的最后一个发稿日
return turnStarts.pop()
}
/*
* 生成器函数
*/
function* gen(turns, all) {
if (typeof turns !== 'number' && typeof all !== 'number') {
return '无效参数。调用示例:g = gen(1)或g = gen(2,\'all\')'
}
const pubDays = []
let time = epoch
while (pubDays.length < turns * writers.length) {
if ('13'.indexOf(new Date(time).getDay()) > -1)
pubDays.push(time)
time += pofday
}
const result = pubDays.map((d, i) => {
const index = i % writers.length
const writer = writers[index]
const date = genDate(d)
return [date, writer]
})
// 如果不是查看全部轮次,则仅返回第turns轮的结果
if (all !== 'all') {
const startIndex = (turns - 1) * writers.length
const currentIteration = result.splice(startIndex, writers.length)
yield currentIteration
return
}
// 如果是查看全部轮次,则依次显示全部轮次
while (turns > 0) {
const startIndex = (turns - 1) * writers.length
const currentIteration = result.splice(startIndex, writers.length)
yield currentIteration
turns--
}
}
function getToday() {
const temp = new Date()
return new Date(temp.getFullYear() + '-' + (temp.getMonth() + 1) + '-' + (temp.getDate()+2) ).valueOf()
}
function genDate(d) {
const temp = new Date(d)
return temp.getFullYear() + '-' + padding((temp.getMonth() + 1)) + '-' + padding(temp.getDate())
}
function padding(v) {
v = String(v)
return v.length === 1 ? '0' + v : v
}
function fmtResult(ret) {
const lis = ret.map(item => {
return `<li><span class="date">${item[0]}</span> ${item[1]}</li>`
}).join('')
return `<ul>${lis}</ul>`
}
// const d = document.getElementById('result')
// const g = gen(2,'all')
// const t1 = g.next().value
// const t2 = g.next().value
// const t3 = g.next().value
// d.innerHTML = fmtResult(t1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment