Skip to content

Commit

Permalink
#2370 Added month_name_to_m
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard Soh committed Dec 22, 2022
1 parent 61e1928 commit 0a5e227
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions met/src/basic/vx_cal/unix_to_mdyhms.cc
Expand Up @@ -16,6 +16,7 @@ using namespace std;

#include <iostream>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <cmath>

Expand Down Expand Up @@ -94,6 +95,35 @@ const char * short_month_name[] = {
};


////////////////////////////////////////////////////////////////////////
// Converts a month string to month (1 to 12).

int month_name_to_m (const char *month_str)

{

int month = -1;
int str_len = strlen(month_str);
char t_month_str[str_len + 1];

for (int idx=0; idx<str_len; idx++) {
t_month_str[idx] = (idx==0) ? toupper(month_str[idx]) : tolower(month_str[idx]);
}
t_month_str[str_len] = 0;

for (int idx=1; idx<=12; idx++) {
if (0 == strcmp(short_month_name[idx], t_month_str)
|| 0 == strcmp(month_name[idx], t_month_str)) {
month = idx;
break;
}
}

return month;

}


////////////////////////////////////////////////////////////////////////


Expand Down
1 change: 1 addition & 0 deletions met/src/basic/vx_cal/vx_cal.h
Expand Up @@ -54,6 +54,7 @@ extern unixtime doyhms_to_unix (int doy, int year, int hour, int minute, int
extern unixtime mdyhms_to_unix (int month, int day, int year, int hour, int minute, int second);

extern void unix_to_mdyhms (unixtime u, int & month, int & day, int & year, int & hour, int & minute, int & second);
extern int month_name_to_m (const char *month_str);


extern int date_to_mjd (int m, int d, int y);
Expand Down

0 comments on commit 0a5e227

Please sign in to comment.