Skip to Content
Odoo मेन्यू
  • Sign in
  • मुफ़्त में आज़माएं
  • ऐप्लिकेशन
    फ़ाइनेंस
    • अकाउंटिंग
    • इनवॉइसिंग
    • एक्सपेंस
    • स्प्रेडशीट (बीआई)
    • डॉक्यूमेंट्स
    • साइन
    सेल्स
    • सीआरएम
    • सेल्स
    • पीओएस शॉप
    • पीओएस रेस्टोरेंट
    • सब्सक्रिप्शन
    • रेंटल
    वेबसाइट
    • वेबसाइट बिल्डर
    • ई-कॉमर्स
    • ब्लॉग
    • फ़ोरम
    • लाइव चैट
    • ई-लर्निंग
    सप्लाई चेन
    • इन्वेंट्री
    • मैन्युफ़ैक्चरिंग
    • पीएलएम
    • परचेज़
    • मेंटेनेंस
    • क्वालिटी
    मानव संसाधन
    • कर्मचारी
    • रिक्रूटमेंट
    • टाइम ऑफ़
    • अप्रेज़ल
    • रेफ़रल
    • फ़्लीट
    मार्केटिंग
    • सोशल मार्केटिंग
    • ईमेल मार्केटिंग
    • एसएमएस मार्केटिंग
    • इवेंट
    • मार्केटिंग ऑटोमेशन
    • सर्वे
    सेवाएं
    • प्रोजेक्ट
    • टाइमशीट
    • फ़ील्ड सर्विस
    • हेल्पडेस्क
    • प्लानिंग
    • अपॉइंटमेंट
    प्रॉडक्टिविटी
    • डिस्कस
    • अप्रूवल
    • आईओटी
    • वीओआईपी
    • नॉलेज
    • WhatsApp
    तीसरे पक्ष के ऐप्लिकेशन Odoo स्टूडियो Odoo क्लाउड प्लेटफ़ॉर्म
  • इंडस्ट्री
    रीटेल
    • बुक स्टोर
    • क्लोदिंग स्टोर
    • फ़र्नीचर स्टोर
    • ग्रॉसरी स्टोर
    • हार्डवेयर स्टोर
    • टॉय स्टोर
    Food & Hospitality
    • बार और पब
    • रेस्टोरेंट
    • फ़ास्ट फ़ूड
    • Guest House
    • बेवरिज डिस्ट्रीब्यूटर
    • होटल
    रियल एस्टेट
    • Real Estate Agency
    • आर्किटेक्चर फ़र्म
    • कंसट्रक्शन
    • एस्टेट मैनेजमेंट
    • गार्ड्निंग
    • प्रॉपर्टी ओनर असोसिएशन
    कंसल्टिंग
    • अकाउंटिंग फ़र्म
    • Odoo पार्टनर
    • मार्केटिंग एजेंसी
    • लॉ फ़र्म
    • टैलेंट ऐक्विज़िशन
    • ऑडिट & सर्टिफ़िकेशन
    मैन्युफ़ैक्चरिंग
    • टेक्सटाइल
    • Metal
    • फ़र्नीचर
    • फ़ूड
    • Brewery
    • कॉर्पोरेट गिफ़्ट
    हेल्थ & फिटनेस
    • स्पोर्ट्स क्लब
    • आईवियर स्टोर
    • फिटनेस सेंटर
    • वेलनेस प्रैक्टिशनर
    • फॉर्मेसी
    • हेयर सैलून
    Trades
    • Handyman
    • आईटी हॉर्डवेयर और सपोर्ट
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    अन्य
    • Nonprofit Organization
    • एन्वायरमेंटल एजेंसी
    • बिलबोर्ड रेंटल
    • फ़ोटोग्राफी
    • बाइक लीजिंग
    • सॉफ़्टवेयर रीसेलर
    Browse all Industries
  • कम्यूनिटी
    सीखें
    • ट्यूटोरियल्स
    • दस्तावेज़
    • सर्टिफ़िकेशन
    • ट्रेनिंग
    • ब्लॉग
    • पॉडकास्ट
    शिक्षा को बढ़ावा दें
    • एजुकेशन प्रोग्राम
    • स्केल अप! बिजनेस गेम
    • Odoo के ऑफ़िस में आएं
    सॉफ़्टवेयर पाएं
    • डाउनलोड
    • वर्शन की तुलना करें
    • रिलीज़
    साथ मिलकर काम करें
    • Github
    • फ़ोरम
    • इवेंट
    • अनुवाद
    • पार्टनर बनें
    • Services for Partners
    • अपना अकाउंटिंग फ़र्म रजिस्टर करें
    सेवाएं पाएं
    • पार्टनर ढूंढें
    • अकाउंटेंट खोजें
    • सलाहकार की मदद लें
    • इम्प्लिमेंटेशन सेवाएं
    • कस्टमर रेफ़रेंस
    • सहायता
    • अपग्रेड
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    डेमो देखें
  • कीमत
  • सहायता

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

  • सीआरएम
  • e-Commerce
  • लेखांकन
  • इन्वेंटरी
  • PoS
  • प्रोजेक्ट
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
Help

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

Subscribe

Get notified when there's activity on this post

This question has been flagged
formattimeoff
2 Replies
3696 Views
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
Discard
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
Discard
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
Discard
Josep Anton Belchi Riera
Author

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!

Sign up
Related Posts Replies Views Activity
How to Allow Employees to View Their Coworkers' Vacations Types
timeoff
Avatar
0
फ़र॰ 25
1399
time off
timeoff
Avatar
0
जुल॰ 24
1677
Odoo 17 enterprise time off 3 steps approval workflow
timeoff
Avatar
Avatar
1
मई 24
3887
Time off 0 days
timeoff
Avatar
Avatar
1
नव॰ 23
1872
How to setup a recurrent time off
timeoff
Avatar
0
दिस॰ 21
4731
कम्यूनिटी
  • ट्यूटोरियल्स
  • दस्तावेज़
  • फ़ोरम
ओपन सोर्स
  • डाउनलोड
  • Github
  • रनबॉट
  • अनुवाद
सेवाएं
  • Odoo.sh Hosting
  • सहायता
  • अपग्रेड
  • कस्टम डेवलपमेंट्स
  • शिक्षा
  • अकाउंटेंट खोजें
  • पार्टनर ढूंढें
  • पार्टनर बनें
हमारे बारे में
  • हमारी कंपनी
  • ब्रांड ऐसेट
  • संपर्क करें
  • नौकरियां
  • इवेंट
  • पॉडकास्ट
  • ब्लॉग
  • ग्राहक
  • लीगल • गोपनीयता
  • सुरक्षा
الْعَرَبيّة 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, बिज़नेस से जुड़े ऐप्लिकेशन का एक कलेक्शन है जो ओपन सोर्स पर आधारित है. इसमें आपकी कंपनी की हर ज़रूरत के लिए ऐप्लिकेशन हैं. जैसे, सीआरएम, ई-कॉमर्स, अकाउंटिंग, इन्वेंट्री, पॉइंट ऑफ़ सेल, प्रोजेक्ट मैनेजमेंट वगैरह.

Odoo की सबसे बड़ी खासियत है कि यह इस्तेमाल करने में बहुत आसान है और यह पूरी तरह से इंटिग्रेट किया हुआ है.

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