mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
(bug) unable to manage stocks on new product
This commit is contained in:
parent
2cf18c277c
commit
2889fb8e12
@ -3,6 +3,7 @@
|
||||
- Accounting data is now built each night and saved in database
|
||||
- OpenAPI endpoint to fetch accounting data
|
||||
- Fix a bug: providing an array of attributes to filter OpenApi data, results in error
|
||||
- Fix a bug: unable to manage stocks on new products
|
||||
- [TODO DEPLOY] `rails fablab:setup:build_accounting_lines`
|
||||
|
||||
- Add reservation deadline parameter (#414)
|
||||
|
@ -5,6 +5,29 @@ import { TDateISO, TDateISODate, THours, TMinutes } from '../typings/date-iso';
|
||||
declare let Fablab: IFablab;
|
||||
|
||||
export default class FormatLib {
|
||||
/**
|
||||
* Check if the provided variable is a JS Date oject
|
||||
*/
|
||||
static isDate = (value: unknown): boolean => {
|
||||
return (value != null) && !isNaN(value as number) && (typeof (value as Date).getDate !== 'undefined');
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the provided variable is an ISO 8601 representation of a date
|
||||
*/
|
||||
static isDateISO = (value: string): boolean => {
|
||||
if (typeof value !== 'string') return false;
|
||||
return !!value?.match(/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\d\d\d/);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the provided variable is string representing a short time, according to ISO 8601 (e.g. 14:21)
|
||||
*/
|
||||
static isShortTimeISO = (value: string): boolean => {
|
||||
if (typeof value !== 'string') return false;
|
||||
return !!value?.match(/^\d\d:\d\d$/);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the formatted localized date for the given date
|
||||
*/
|
||||
@ -17,8 +40,8 @@ export default class FormatLib {
|
||||
*/
|
||||
static time = (date: Date|TDateISO|`${THours}:${TMinutes}`): string => {
|
||||
let tempDate: Date;
|
||||
const isoTimeMatch = (date as string)?.match(/^(\d\d):(\d\d)$/);
|
||||
if (isoTimeMatch) {
|
||||
if (FormatLib.isShortTimeISO(date as string)) {
|
||||
const isoTimeMatch = (date as string)?.match(/^(\d\d):(\d\d)$/);
|
||||
tempDate = new Date();
|
||||
tempDate.setHours(parseInt(isoTimeMatch[1], 10));
|
||||
tempDate.setMinutes(parseInt(isoTimeMatch[2], 10));
|
||||
|
Loading…
x
Reference in New Issue
Block a user