Skip to content
Snippets Groups Projects
Commit 388d4ff3 authored by LIOTIER MARION's avatar LIOTIER MARION
Browse files

debug date as string

parent 33d3dffd
No related branches found
No related tags found
No related merge requests found
Pipeline #301541 passed with warnings
......@@ -75,18 +75,25 @@
</template>
<script setup lang="ts">
import { ref, reactive } from "vue";
import { ref, reactive, computed } from "vue";
import { useDisplay } from "vuetify";
import type { User } from "@/types/User";
import { dateAsString } from "@/composables/utils";
// V MODEL
const errorMessage = defineModel<string | undefined>();
// COMPUTED
const currentDateAsString = computed((): string => {
const d = new Date();
return dateAsString(d);
});
// DATA
const form = reactive<User>({
login: "",
password: "",
last_visit_date: currentDateAsString(),
last_visit_date: currentDateAsString.value,
registration_date: "2024-09-23 09:28:00",
});
const isValid = ref<boolean>();
......@@ -97,10 +104,6 @@ const { mdAndUp } = useDisplay();
const emits = defineEmits(["submit"]);
// METHODS
function currentDateAsString() {
const d = new Date();
return `${d.getFullYear()}-${("0" + d.getMonth()).slice(-2)}-${d.getDate()} ${("0" + d.getHours()).slice(-2)}:${("0" + d.getMinutes()).slice(-2)}:${("0" + d.getSeconds()).slice(-2)}`;
}
/**
* Rule for a non null input
* @returns rule
......
// Copyright 2025 INRAE
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { describe, test, expect } from "vitest";
import { dateAsString } from "../utils";
describe("dateAsString", () => {
test("should return the date as string : January 1, 2025 00:00:00", () => {
const d = new Date("January 1, 2025 00:00:00");
expect(dateAsString(d)).toBe("2025-01-01 00:00:00");
});
test("should return the date as string : March 20, 2025 10:30:00", () => {
const d = new Date("March 20, 2025 10:30:00");
expect(dateAsString(d)).toBe("2025-03-20 10:30:00");
});
test("should return the date as string : December 5, 2025 23:59:59", () => {
const d = new Date("December 5, 2025 23:59:59");
expect(dateAsString(d)).toBe("2025-12-05 23:59:59");
});
});
// Copyright 2025 INRAE
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* Returns a date as a string 'YYYY-MM-DD HH:MM:SS'
* @param d a date
* @returns the date as a string
*/
export function dateAsString(d: Date): string {
return `${d.getFullYear()}-${("0" + (d.getMonth() + 1)).slice(-2)}-${("0" + d.getDate()).slice(-2)} ${("0" + d.getHours()).slice(-2)}:${("0" + d.getMinutes()).slice(-2)}:${("0" + d.getSeconds()).slice(-2)}`;
}
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