REFACTOR
This commit is contained in:
parent
0460b2e9f7
commit
176483d72f
59 changed files with 11 additions and 45 deletions
src/models
46
src/models/period.c
Normal file
46
src/models/period.c
Normal file
|
@ -0,0 +1,46 @@
|
|||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <models/period.h>
|
||||
|
||||
int
|
||||
period_helper_parse_hhmm(const char *hhmm_str, uint16_t *hhmm)
|
||||
{
|
||||
if(strlen(hhmm_str) != 5)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if(hhmm_str[2] != ':')
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
for(int i = 0; i < 5; ++i)
|
||||
{
|
||||
if(i != 2)
|
||||
{
|
||||
if(hhmm_str[i] < '0' || hhmm_str[i] > '9')
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t tmp_h, tmp_m;
|
||||
tmp_h = (uint16_t)strtol(&hhmm_str[0], NULL, 10);
|
||||
tmp_m = (uint16_t)strtol(&hhmm_str[3], NULL, 10);
|
||||
|
||||
if(tmp_h > 24 || tmp_m >= 60)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if(tmp_h == 24 && tmp_m > 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
*hhmm = (tmp_h * 60) + tmp_m;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue