Skip to content

Commit

Permalink
[Fix #529] Ignore month case in parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
vspinu committed May 6, 2017
1 parent 5fe60e0 commit c5c3ae3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Version 1.6.0.9000
==================

### NEW FEATURES
* [#529](https://github.com/hadley/lubridate/issues/529) Internal parser now ignores the case of alpha months (B format)
* [#535](https://github.com/hadley/lubridate/issues/535) Rounding to `season` is now supported.
* [#536](https://github.com/hadley/lubridate/issues/536) `as_date` and `as_datetime` now understand character vectors.
* [#508](https://github.com/hadley/lubridate/pull/508) New parameter `locale` in `month`. Labels of the returned factors (when `label=TRUE`) now respect current locale.
Expand All @@ -11,7 +12,6 @@ Version 1.6.0.9000
* [#401](https://github.com/hadley/lubridate/issues/401) New parameter `locale` in `wday`. Labels of the returned factors (when `label=TRUE`) now respect current locale.

### BUG FIXES

* [#530](https://github.com/hadley/lubridate/issues/530) `parse_date_time` now throw warnings only for actual parsing errors (input with all NAs are silent)
* [#534](https://github.com/hadley/lubridate/issues/534) Fix arithmetics with large numbers
* [#507](https://github.com/hadley/lubridate/issues/507) Period and duration parsers now understand 0 units.
Expand Down
4 changes: 2 additions & 2 deletions src/tparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@


static const char ltnames[][5] = {"sec", "min", "hour", "mday", "mon", "year"};
static const char *en_months[] = {"January", "February","March","April","May","June",
"July","August","September","October","November","December"};
static const char *en_months[] = {"january", "february","march","april","may","june",
"july","august","september","october","november","december"};

// increment **c and return month ix in 1..12 if parsing was successful, 0 if not.
int parse_alpha_month(const char **c){
Expand Down
7 changes: 4 additions & 3 deletions src/utils.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "constants.h"
#include "utils.h"
#include <stdio.h>
#include <ctype.h>

// return adjustment (in seconds) due to leap years
// y: years after (positive) or before (negative) 2000-01-01 00:00:00
Expand Down Expand Up @@ -59,10 +60,10 @@ int parse_int (const char **c, const int N, const int strict) {
}


// Increment **c and return index in 0..length(strings) if match was found, -1
// Increment *c and return index in 0..length(strings) if match was found, -1
// if not.
//
// - **c: pointer to a character in a C string (automatically incremented)
// - *c: pointer to a character in a C string (incremented by side effect)
// - *stings: pointer to an array of C strings to be matched to.
// - strings_len: length of strings array.
int parse_alphanum(const char **c, const char **strings, const int strings_len){
Expand All @@ -83,7 +84,7 @@ int parse_alphanum(const char **c, const char **strings, const int strings_len){
if (track[i]){
// keep going while at least one valid track
if (strings[i][j]){
if(**c == strings[i][j]){
if(**c == strings[i][j] || tolower(**c) == strings[i][j]){
out = i;
go = 1;
} else {
Expand Down
7 changes: 6 additions & 1 deletion tests/testthat/test-parsers.R
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,12 @@ test_that("`parse_date_time` parses heterogeneous formats with `exact=TRUE`", {
tz = "UTC"))
})


test_that("parser ignores case", {
ref <- ymd_hms("2016-01-04 07:40:00", "2016-01-04 07:40:00", "2016-01-04 07:40:00 UTC")
dts <- c("04jan2016:07:40:00", "04JAN2016:07:40:00", "04Jan2016:07:40:00")
expect_equal(ref, parse_date_time2(dts, "dBYHMS"))
expect_equal(ref, dmy_hms(dts))
})

## library(microbenchmark)
## library(lubridate)
Expand Down

0 comments on commit c5c3ae3

Please sign in to comment.