mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
add items per wagon map to cargo types and sync bulk rate units
- Implemented in the to manage the physical item capacity for each wagon type. - Added a new migration to create the column in the table. - Introduced method in to update rate units when cargo type unit of measure changes. - Updated booking calculations to consider items per wagon for break-bulk cargo. - Refactored various components to utilize the new items fit logic and ensure consistent date formatting across the application. - Added tests for the new display timezone functionality to ensure consistent date/time representation across different user settings.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
"types": "./src/index.ts",
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./display-timezone": "./src/lib/display-timezone.ts",
|
||||
"./styles.css": "./dist/index.css",
|
||||
"./theme.css": "./src/styles/theme.css"
|
||||
},
|
||||
|
||||
48
packages/ui-common/src/lib/display-timezone.ts
Normal file
48
packages/ui-common/src/lib/display-timezone.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Side-effect module: pins every Intl-based date/time display to East Africa
|
||||
* Time (UTC+3) so all users see the same wall-clock times no matter what
|
||||
* timezone their PC is set to. Import it FIRST in the app entry, before any
|
||||
* other app module, so no module-scope formatter is created unpatched:
|
||||
*
|
||||
* import "@edr/ui-common/display-timezone";
|
||||
*
|
||||
* Call sites that pass an explicit `timeZone` option keep it. date-fns and
|
||||
* dayjs `format()` do NOT go through Intl and stay PC-local — don't use them
|
||||
* to display API timestamps.
|
||||
*/
|
||||
export const DISPLAY_TIME_ZONE = "Africa/Addis_Ababa";
|
||||
|
||||
type Locales = string | string[] | undefined;
|
||||
type LocaleMethod = (
|
||||
this: Date,
|
||||
locales?: Locales,
|
||||
options?: Intl.DateTimeFormatOptions,
|
||||
) => string;
|
||||
|
||||
function pinned(original: LocaleMethod): LocaleMethod {
|
||||
return function (locales, options) {
|
||||
return original.call(this, locales, {
|
||||
...options,
|
||||
timeZone: options?.timeZone ?? DISPLAY_TIME_ZONE,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
Date.prototype.toLocaleString = pinned(Date.prototype.toLocaleString);
|
||||
Date.prototype.toLocaleDateString = pinned(Date.prototype.toLocaleDateString);
|
||||
Date.prototype.toLocaleTimeString = pinned(Date.prototype.toLocaleTimeString);
|
||||
|
||||
const OriginalDateTimeFormat = Intl.DateTimeFormat;
|
||||
function PinnedDateTimeFormat(
|
||||
locales?: Locales,
|
||||
options?: Intl.DateTimeFormatOptions,
|
||||
): Intl.DateTimeFormat {
|
||||
return new OriginalDateTimeFormat(locales, {
|
||||
...options,
|
||||
timeZone: options?.timeZone ?? DISPLAY_TIME_ZONE,
|
||||
});
|
||||
}
|
||||
// Keep `instanceof Intl.DateTimeFormat` and the static method working.
|
||||
PinnedDateTimeFormat.prototype = OriginalDateTimeFormat.prototype;
|
||||
PinnedDateTimeFormat.supportedLocalesOf = OriginalDateTimeFormat.supportedLocalesOf;
|
||||
Intl.DateTimeFormat = PinnedDateTimeFormat as unknown as typeof Intl.DateTimeFormat;
|
||||
Reference in New Issue
Block a user