Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

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

Subscriure's

Get notified when there's activity on this post

This question has been flagged
formattimeoff
2 Respostes
3675 Vistes
Avatar
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
Avatar
Descartar
Avatar
Tim Altendorf
Best Answer

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
Avatar
Descartar
Avatar
Vlads
Best Answer

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
Avatar
Descartar
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

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
How to Allow Employees to View Their Coworkers' Vacations Types
timeoff
Avatar
0
de febr. 25
1394
time off
timeoff
Avatar
0
de jul. 24
1670
Odoo 17 enterprise time off 3 steps approval workflow
timeoff
Avatar
Avatar
1
de maig 24
3872
Time off 0 days
timeoff
Avatar
Avatar
1
de nov. 23
1870
How to setup a recurrent time off
timeoff
Avatar
0
de des. 21
4718
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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