diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-04-25 21:53:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-25 21:53:42 +0200 |
| commit | 128f76f7fd7c8abb41a3bbbd9f1980cbc20ae7a5 (patch) | |
| tree | add513890005233a7784466797bfe6f5052e9eeb /opendc-web/opendc-web-ui/src/util/date-time.test.js | |
| parent | 128a1db017545597a5c035b7960eb3fd36b5f987 (diff) | |
| parent | 57b54b59ed74ec37338ae26b3864d051255aba49 (diff) | |
build: Flatten project structure
This change updates the project structure to become flattened.
Previously, the simulator, frontend and API each lived into their own directory.
With this change, all modules of the project live in the top-level directory of
the repository.
Diffstat (limited to 'opendc-web/opendc-web-ui/src/util/date-time.test.js')
| -rw-r--r-- | opendc-web/opendc-web-ui/src/util/date-time.test.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/opendc-web/opendc-web-ui/src/util/date-time.test.js b/opendc-web/opendc-web-ui/src/util/date-time.test.js new file mode 100644 index 00000000..3d95eba6 --- /dev/null +++ b/opendc-web/opendc-web-ui/src/util/date-time.test.js @@ -0,0 +1,35 @@ +import { convertSecondsToFormattedTime, parseDateTime } from './date-time' + +describe('date-time parsing', () => { + it('reads components properly', () => { + const dateString = '2017-09-27T20:55:01' + const parsedDate = parseDateTime(dateString) + + expect(parsedDate.getUTCFullYear()).toEqual(2017) + expect(parsedDate.getUTCMonth()).toEqual(8) + expect(parsedDate.getUTCDate()).toEqual(27) + expect(parsedDate.getUTCHours()).toEqual(20) + expect(parsedDate.getUTCMinutes()).toEqual(55) + expect(parsedDate.getUTCSeconds()).toEqual(1) + }) +}) + +describe('tick formatting', () => { + it("returns '0s' for numbers <= 0", () => { + expect(convertSecondsToFormattedTime(-1)).toEqual('0s') + expect(convertSecondsToFormattedTime(0)).toEqual('0s') + }) + it('returns only seconds for values under a minute', () => { + expect(convertSecondsToFormattedTime(1)).toEqual('1s') + expect(convertSecondsToFormattedTime(59)).toEqual('59s') + }) + it('returns seconds and minutes for values under an hour', () => { + expect(convertSecondsToFormattedTime(60)).toEqual('1m00s') + expect(convertSecondsToFormattedTime(61)).toEqual('1m01s') + expect(convertSecondsToFormattedTime(3599)).toEqual('59m59s') + }) + it('returns full time for values over an hour', () => { + expect(convertSecondsToFormattedTime(3600)).toEqual('1h00m00s') + expect(convertSecondsToFormattedTime(3601)).toEqual('1h00m01s') + }) +}) |
