Example #1
0
export function formatDate(date) {
	return (d3Time.timeSecond(date) < date ? FORMAT_MILLISECOND
		: d3Time.timeMinute(date) < date ? FORMAT_SECOND
		: d3Time.timeHour(date) < date ? FORMAT_MINUTE
		: d3Time.timeDay(date) < date ? FORMAT_HOUR
		: d3Time.timeMonth(date) < date ? (d3Time.timeWeek(date) < date ? FORMAT_DAY : FORMAT_WEEK)
		: d3Time.timeYear(date) < date ? FORMAT_MONTH
		: FORMAT_YEAR)(date);
}
 return (function (date) {
     return (timeSecond(date) < date ? timeFormat(millisecond)
         : timeMinute(date) < date ? timeFormat(second)
             : timeHour(date) < date ? timeFormat(minute)
                 : timeDay(date) < date ? timeFormat(hour)
                     : timeMonth(date) < date ? (timeWeek(date) < date ? timeFormat(day) : timeFormat(week))
                         : timeYear(date) < date ? timeFormat(month)
                             : timeFormat(year))(date);
 });
Example #3
0
    return (originX, originY, d, yearIndex) => {
        const weekOfYear = timeWeek.count(timeYear(d), d)

        return {
            x:
                originX +
                d.getDay() * (cellSize + daySpacing) +
                daySpacing / 2 +
                yearIndex * (yearSpacing + 7 * (cellSize + daySpacing)),
            y: originY + weekOfYear * (cellSize + daySpacing) + daySpacing / 2,
        }
    }
Example #4
0
function formatWeekNumberMonday(d, p) {
  return pad(timeMonday.count(timeYear(d), d), p, 2);
}
Example #5
0
function formatWeekNumberISO(d, p) {
  var day = d.getDay();
  d = (day >= 4 || day === 0) ? timeThursday(d) : timeThursday.ceil(d);
  return pad(timeThursday.count(timeYear(d), d) + (timeYear(d).getDay() === 4), p, 2);
}
Example #6
0
function formatDayOfYear(d, p) {
  return pad(1 + timeDay.count(timeYear(d), d), p, 3);
}
Example #7
0
const monthPathAndBBox = ({
    date,
    cellSize,
    yearIndex,
    yearSpacing,
    daySpacing,
    direction,
    originX,
    originY,
}) => {
    // first day of next month
    const t1 = new Date(date.getFullYear(), date.getMonth() + 1, 0)

    // ranges
    const firstWeek = timeWeek.count(timeYear(date), date)
    const lastWeek = timeWeek.count(timeYear(t1), t1)
    const firstDay = date.getDay()
    const lastDay = t1.getDay()

    // offset according to year index
    let xO = originX
    let yO = originY
    const yearOffset = yearIndex * (7 * (cellSize + daySpacing) + yearSpacing)
    if (direction === 'horizontal') {
        yO += yearOffset
    } else {
        xO += yearOffset
    }

    let path
    let bbox = { x: xO, y: yO, width: 0, height: 0 }
    if (direction === 'horizontal') {
        path = [
            `M${xO + (firstWeek + 1) * (cellSize + daySpacing)},${yO +
                firstDay * (cellSize + daySpacing)}`,
            `H${xO + firstWeek * (cellSize + daySpacing)}V${yO + 7 * (cellSize + daySpacing)}`,
            `H${xO + lastWeek * (cellSize + daySpacing)}V${yO +
                (lastDay + 1) * (cellSize + daySpacing)}`,
            `H${xO + (lastWeek + 1) * (cellSize + daySpacing)}V${yO}`,
            `H${xO + (firstWeek + 1) * (cellSize + daySpacing)}Z`,
        ].join('')

        bbox.x = xO + firstWeek * (cellSize + daySpacing)
        bbox.width = xO + (lastWeek + 1) * (cellSize + daySpacing) - bbox.x
        bbox.height = 7 * (cellSize + daySpacing)
    } else {
        path = [
            `M${xO + firstDay * (cellSize + daySpacing)},${yO +
                (firstWeek + 1) * (cellSize + daySpacing)}`,
            `H${xO}V${yO + (lastWeek + 1) * (cellSize + daySpacing)}`,
            `H${xO + (lastDay + 1) * (cellSize + daySpacing)}V${yO +
                lastWeek * (cellSize + daySpacing)}`,
            `H${xO + 7 * (cellSize + daySpacing)}V${yO + firstWeek * (cellSize + daySpacing)}`,
            `H${xO + firstDay * (cellSize + daySpacing)}Z`,
        ].join('')

        bbox.y = yO + firstWeek * (cellSize + daySpacing)
        bbox.width = 7 * (cellSize + daySpacing)
        bbox.height = yO + (lastWeek + 1) * (cellSize + daySpacing) - bbox.y
    }

    return { path, bbox }
}