Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

Is it possible to change the time format (AM-PM) to a 24h format in time-off requests?

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
formattimeoff
2 Odpowiedzi
3693 Widoki
Awatar
Josep Anton Belchi Riera

In the entire application the time format used is 24h. In contrast, in Time Off app the type used is AM-PM. Is it possible to change this to use a 24h format everywhere?

0
Awatar
Odrzuć
Awatar
Tim Altendorf
Najlepsza odpowiedź

I made an account just for this and the one person that will have the same problem. 

The problem is that in the frontend odoo only uses the locale language code and not the time format options. 

If you know how to develop modules you can add the following code to the static code and add the file to your web.assets_backend then odoo will also respect the time format in chatter, forms and discuss. 

If anyoe else needs this and can't develop their own addons I could wrap it in an odoo 18 addon and make it public. Just respond to this. :)

/** @odoo-module */


import { user } from "@web/core/user";

import { _t } from "@web/core/l10n/translation";

import { rpc } from "@web/core/network/rpc";

import { session } from "@web/session";


// Cache for language formats to avoid repeated server calls

const langFormatCache = {};


/**

* Gets the user's preferred time format from res_lang model

* @returns {Promise<string>} The time format string (e.g. '%H:%M')

*/

async function getUserTimeFormat() {

// Check if we already have the format in cache

let userLang = user.lang || session.user_context.lang || 'en_US';


userLang = userLang.replace('-', '_');

if (langFormatCache[userLang]) {

return langFormatCache[userLang];

}


try {

// Query the server for language settings

const langData = await rpc('/web/dataset/call_kw', {

model: 'res.lang',

method: 'search_read',

args: [[['code', '=', userLang]], ['code', 'time_format', 'date_format', 'short_time_format']],

kwargs: {},

});

if (langData && langData.length) {

const timeFormat = langData[0].time_format || '%H:%M';

const shortTimeFormat = langData[0].short_time_format || '%H:%M';

// Cache the result

langFormatCache[userLang] = {

timeFormat,

shortTimeFormat

};

return langFormatCache[userLang];

}

return {

timeFormat: '%H:%M:%S', // Default format if not found

shortTimeFormat: '%H:%M'

};

} catch (error) {

return {

timeFormat: '%H:%M:%S', // Default format in case of errors

shortTimeFormat: '%H:%M'

}; // Return default formats in case of errors

}

}


// Translation function to convert from DateTime object to user-defined format

function formatTimeAccordingToUserPreferences(dateTime, hasSeconds, timeFormat = {

shortTimeFormat: '%H:%M',

timeFormat: '%H:%M:%S'

}) {

if (!dateTime) return '';


const localTimeFormat = hasSeconds ? timeFormat.timeFormat : timeFormat.shortTimeFormat;


// Extract hour and minute values from DateTime object

const hour = dateTime.hour;

const minute = dateTime.minute;

const second = dateTime.second;

// Handle different format placeholders

let formattedTime = localTimeFormat;

// Handle 24-hour format

formattedTime = formattedTime.replace(/%H/g, hour.toString().padStart(2, '0')); // 24h with leading zero

formattedTime = formattedTime.replace(/%k/g, hour.toString()); // 24h without leading zero

// Handle 12-hour format

const hour12 = hour % 12 || 12;

formattedTime = formattedTime.replace(/%I/g, hour12.toString().padStart(2, '0')); // 12h with leading zero

formattedTime = formattedTime.replace(/%l/g, hour12.toString()); // 12h without leading zero

// Handle minutes and seconds

formattedTime = formattedTime.replace(/%M/g, minute.toString().padStart(2, '0')); // Minutes with leading zero

formattedTime = formattedTime.replace(/%S/g, second.toString().padStart(2, '0')); // Seconds with leading zero

// Handle AM/PM indicator

const ampm = hour >= 12 ? 'PM' : 'AM';

formattedTime = formattedTime.replace(/%p/g, ampm); // AM/PM uppercase

formattedTime = formattedTime.replace(/%P/g, ampm.toLowerCase()); // am/pm lowercase

return formattedTime;

}


// Global Luxon patch

const patchLuxon = async function() {

if (!window.luxon || !window.luxon.DateTime) {

setTimeout(patchLuxon, 500);

return;

}


const userTimeFormat = await getUserTimeFormat();

const { DateTime } = window.luxon;

// Store the original toLocaleString method

const originalToLocaleString = DateTime.prototype.toLocaleString;

// Replace it with our own implementation

DateTime.prototype.toLocaleString = function(formatOpts, opts = {}) {

// Check if formatOpts is an object with time components

if (formatOpts && typeof formatOpts === 'object') {

const hasTimeComponents = formatOpts.hour !== undefined ||

formatOpts.minute !== undefined ||

formatOpts.second !== undefined;

if (hasTimeComponents) {

// Create a copy of format options without time components

const dateOnlyFormatOpts = { ...formatOpts };

delete dateOnlyFormatOpts.hour;

delete dateOnlyFormatOpts.minute;

const userHasSeconds = dateOnlyFormatOpts.second !== undefined;

delete dateOnlyFormatOpts.second;

let result = '';

// Only format the date part if there are date components left

const hasDateComponents = Object.keys(dateOnlyFormatOpts).length > 0;

if (hasDateComponents) {

// Get date portion using original formatter with date-only options

const datePart = originalToLocaleString.call(this, dateOnlyFormatOpts, opts);

result = datePart;

}

// Format time using our custom formatter

const timePart = formatTimeAccordingToUserPreferences(this, userHasSeconds, userTimeFormat);

// Combine date and time parts

if (hasDateComponents) {

// Only add separator if we have both date and time

result += ', ' + timePart;

} else {

result = timePart;

}

return result;

}

}

// Handle predefined formats like DateTime.TIME_SIMPLE

else if (formatOpts === DateTime.TIME_SIMPLE ||

formatOpts === DateTime.TIME_WITH_SECONDS) {

// These are time-only formats, use our custom formatter

return formatTimeAccordingToUserPreferences(this, userHasSeconds, userTimeFormat);

}

else if (formatOpts === DateTime.DATETIME_SHORT ||

formatOpts === DateTime.DATETIME_MED) {

// These are combined date+time formats

// Split into date and time parts for separate formatting

// First get original result

const originalResult = originalToLocaleString.call(this, formatOpts, opts);

// Then try to extract date part

const parts = originalResult.split(/,\s*|\s+at\s+|\s+/);

if (parts.length > 1) {

const datePart = parts[0];

const timePart = formatTimeAccordingToUserPreferences(this, userHasSeconds, userTimeFormat);

return `${datePart} ${timePart}`;

}

}

// For non-time formats or predefined formats we don't handle,

// use the original implementation;

return originalToLocaleString.call(this, formatOpts, opts);

};


};


// Execute patch when DOM is ready

document.addEventListener('DOMContentLoaded', () => {

// Patch Luxon globally

patchLuxon();

});

0
Awatar
Odrzuć
Awatar
Vlads
Najlepsza odpowiedź

I guess you are using English(US) and custom time format. In that case it won`t affect the date+time format in Time-Off. 

Changing language to English (UK) solves problem.

0
Awatar
Odrzuć
Josep Anton Belchi Riera
Autor

We are using Catalan and Spanish languages. The time format is the expected on the whole aplication.
However, on the Time Off app the time format is AM-PM.
It is the latter that we would like to change so that the time format is the same throughout Odoo.

Vlads

This is just a workaround that works for us.
Good luck waiting help from odoo

Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
How to Allow Employees to View Their Coworkers' Vacations Types
timeoff
Awatar
0
lut 25
1399
time off
timeoff
Awatar
0
lip 24
1676
Odoo 17 enterprise time off 3 steps approval workflow
timeoff
Awatar
Awatar
1
maj 24
3885
Time off 0 days
timeoff
Awatar
Awatar
1
lis 23
1872
How to setup a recurrent time off
timeoff
Awatar
0
gru 21
4731
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now