diff --git a/CHANGELOG.md b/CHANGELOG.md index b8c5c75..b1be81a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [0.35.2](https://github.com/Fantom-foundation/Fantom-Vue3-Components/compare/v0.35.1...v0.35.2) (2023-09-07) + + +### Features + +* create `roundDownTo` date helper function ([d1e4f0a](https://github.com/Fantom-foundation/Fantom-Vue3-Components/commit/d1e4f0a5d41059bb92213ec9f074766b9d53b033)) + ### [0.35.1](https://github.com/Fantom-foundation/Fantom-Vue3-Components/compare/v0.35.0...v0.35.1) (2023-08-21) ## [0.35.0](https://github.com/Fantom-foundation/Fantom-Vue3-Components/compare/v0.34.0...v0.35.0) (2023-08-21) diff --git a/package-lock.json b/package-lock.json index 94063f0..bfd13ba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "fantom-vue3-components", - "version": "0.35.1", + "version": "0.35.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "fantom-vue3-components", - "version": "0.35.1", + "version": "0.35.2", "license": "MIT", "dependencies": { "@vueuse/core": "^8.5.0", diff --git a/package.json b/package.json index c8f579c..ce1cea3 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fantom-vue3-components", - "version": "0.35.1", + "version": "0.35.2", "description": "Library of various Vue 3 components with focus on accessibility", "author": "Fantom Foundation", "license": "MIT", diff --git a/src/utils/date/date.js b/src/utils/date/date.js index da03493..499c8fc 100644 --- a/src/utils/date/date.js +++ b/src/utils/date/date.js @@ -54,3 +54,15 @@ export function timestampToMilliseconds(timestamp) { return ts; } + +/** + * @param {number} timestamp + * @return {number} Timestamp in milliseconds + */ +export function roundDownTo(timestamp, intervalMs = SECOND) { + const date = new Date(Math.floor(timestamp / intervalMs) * intervalMs); + + // date.setSeconds(0); + + return date.valueOf(); +} diff --git a/src/utils/date/date.spec.js b/src/utils/date/date.spec.js index 86a68a1..e0dbd83 100644 --- a/src/utils/date/date.spec.js +++ b/src/utils/date/date.spec.js @@ -1,5 +1,12 @@ import { describe, it, expect } from 'vitest'; -import { getDatesDiff, timestampToSeconds, timestampToMilliseconds } from '@/utils/date/date.js'; +import { + getDatesDiff, + timestampToSeconds, + timestampToMilliseconds, + roundDownTo, + SECOND, + MINUTE, +} from '@/utils/date/date.js'; describe('date utils', () => { describe('getDatesDiff()', () => { @@ -44,4 +51,11 @@ describe('date utils', () => { expect(timestampToMilliseconds(1653488111000000)).toBe(1653488111000); }); }); + + describe('#roundDownTo', () => { + it('should round given timestamp down to given time in milliseconds', () => { + expect(roundDownTo(1653488111222, SECOND)).toBe(1653488111000); + expect(roundDownTo(1653488111000, MINUTE)).toBe(1653488100000); + }); + }); });