Gisle Aune
3 years ago
12 changed files with 105 additions and 17 deletions
-
6src/lib/components/colors.sass
-
6src/lib/components/frontpage/ItemLink.svelte
-
11src/lib/components/frontpage/SprintLink.svelte
-
2src/lib/components/layout/Entry.svelte
-
2src/lib/components/layout/EntryAmounts.svelte
-
2src/lib/components/layout/EntryBgIcon.svelte
-
67src/lib/components/layout/EntryDate.svelte
-
3src/lib/components/layout/EntryName.svelte
-
9src/lib/components/layout/EntryProgress.svelte
-
1src/lib/models/item.ts
-
8src/routes/index.svelte
-
5src/routes/indexdata.json.ts
@ -0,0 +1,67 @@ |
|||
<script lang="ts"> |
|||
import currentTime from "$lib/stores/currentTime"; |
|||
export let value: Date | string; |
|||
export let green: boolean = false; |
|||
export let verb: string = "Created"; |
|||
|
|||
let dateStr = ""; |
|||
let timeStr = ""; |
|||
|
|||
$: { |
|||
const date = (value instanceof Date) ? value : new Date(value); |
|||
const today = new Date($currentTime.getFullYear(), $currentTime.getMonth(), $currentTime.getDate(), 0, 0, 0, 0); |
|||
const thisYear = new Date($currentTime.getFullYear(), 0, 1, 0, 0, 0, 0); |
|||
const nextYear = new Date($currentTime.getFullYear()+1, 0, 1, 0, 0, 0, 0); |
|||
const offset = date.getTime() - today.getTime(); |
|||
|
|||
if (offset >= DAY * 2 || offset < DAY * -1) { |
|||
if (date < thisYear || date >= nextYear) { |
|||
dateStr = `${date.getDate()} ${MONTHS[date.getMonth()]} ${date.getFullYear()}` |
|||
} else { |
|||
dateStr = `${date.getDate()} ${MONTHS[date.getMonth()]}` |
|||
} |
|||
} else if (offset >= DAY * 1) { |
|||
dateStr = "tomrrow"; |
|||
} else if (offset >= 0) { |
|||
dateStr = "today"; |
|||
} else { |
|||
dateStr = "yesterday"; |
|||
} |
|||
|
|||
timeStr = `${pad(date.getHours())}:${pad(date.getMinutes())}` |
|||
} |
|||
</script> |
|||
|
|||
<div class="date" class:green> |
|||
<span class="verb">{verb}</span> |
|||
<span class="value">{dateStr}</span> |
|||
<span class="verb">at</span> |
|||
<span class="value">{timeStr}</span> |
|||
</div> |
|||
|
|||
<style lang="scss"> |
|||
@import "../colors.sass"; |
|||
|
|||
div.date { |
|||
font-size: 0.75em; |
|||
font-weight: 600; |
|||
|
|||
&.green { |
|||
color: $color-green; |
|||
} |
|||
|
|||
> span.verb { |
|||
opacity: $opacity-entry4; |
|||
} |
|||
> span.value { |
|||
opacity: $opacity-entry5; |
|||
} |
|||
} |
|||
</style> |
|||
|
|||
<script lang="ts" context="module"> |
|||
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; |
|||
const DAY = 86400000; |
|||
|
|||
function pad(n: number) { return n > 10 ? n.toString() : `0${n}` }; |
|||
</script> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue