Skip to content
Snippets Groups Projects
Commit 1159d9f3 authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

feat: add useFormattedISODate helper function

parent 3a6a75b4
No related branches found
No related tags found
No related merge requests found
import { cloneDeep, isEqual } from 'lodash' import { cloneDeep, isEqual } from 'lodash'
import { computed, ComputedGetter, ComputedRef, readonly, Ref, ref, watch, watchEffect } from 'vue' import { computed, ComputedGetter, ComputedRef, readonly, Ref, ref, watch, watchEffect } from 'vue'
import { formatISO, parseISO } from 'date-fns'
export function computedIter<T>(fn: ComputedGetter<Iterable<T>>): ComputedRef<T[]> { export function computedIter<T>(fn: ComputedGetter<Iterable<T>>): ComputedRef<T[]> {
return computed(() => Array.from(fn())) return computed(() => Array.from(fn()))
...@@ -47,3 +48,14 @@ export function useUpdatableState<T>( ...@@ -47,3 +48,14 @@ export function useUpdatableState<T>(
) )
return localRef return localRef
} }
export function useFormattedISODate(date: Ref<Date>) {
return computed({
get() {
return formatISO(date.value, { representation: 'date' })
},
set(dateValue: string) {
date.value = parseISO(dateValue)
},
})
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment