<commit_before>package tars.commons.util;

/**
 * Date Time Utility package
 * @@author A0121533W
 *
 */
public class DateTimeUtil {
    /**
     * Extracts the new task's dateTime from the string arguments.
     * @return String[] with first index being the startDate time 
     * and second index being the end date time
     */
    public static String[] getDateTimeFromArgs(String taskArguments) {
        if (taskArguments.equals("")) {
            return new String[] {"", ""};
        } else if (taskArguments.contains("to")) {
            int toIndex = taskArguments.indexOf("to");
            String startDateTime = taskArguments.substring(0, toIndex).trim();
            String endDateTime = taskArguments.substring(toIndex + 2).trim();
            return new String[] {startDateTime, endDateTime};
        } else {
            return new String[] {"", taskArguments.trim()};
        }
    }
}<commit_msg>Implement natty date parser<commit_after>package tars.commons.util;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

import com.joestelmach.natty.DateGroup;
import com.joestelmach.natty.Parser;

/**
 * Date Time Utility package
 * 
 * @@author A0139924W
 */
public class DateTimeUtil {
    private static final SimpleDateFormat CONVERT_NATTY_TIME_FORMAT = new SimpleDateFormat("dd/MM/yyyy HHmm");
    
    /**
     * Extracts the new task's dateTime from the string arguments using natty.
     * 
     * @return String[] with first index being the startDate time and second index being the end
     *         date time
     */
    public static String[] getDateTimeFromArgs(String dateArgs) {
        List<Date> dateList = new ArrayList<Date>();
        Parser parser = new Parser(TimeZone.getDefault());
        
        // swap the date format as natty read dates in US format
        List<DateGroup> groups = parser.parse(dateArgs
                .trim()
                .replaceAll("(\\b\\d{1,2})/(\\d{1,2})", "$2/$1")
                .replaceAll("(\\b\\d{1,2})-(\\d{1,2})", "$2-$1")
        );
        
        System.out.println(dateArgs.trim());
        System.out.println("after: " + dateArgs.trim()
                .replaceAll("(^[a-zA-Z_ ]*\\d{1,2})/(\\d{1,2})", "$2/$1")
                .replaceAll("(^[a-zA-Z_ ]*\\d{1,2})-(\\d{1,2})", "$2-$1"));
        for (DateGroup group : groups) {
            dateList.addAll(group.getDates());
        }
        
        // invalid date format, will pass the datetime to handle it
        if (dateArgs.trim().length() > 0 && dateList.size() == 0) {
            return new String[] { "", dateArgs };
        }
        
        if(dateList.size() == 1) {
            String endDateTime = CONVERT_NATTY_TIME_FORMAT.format(dateList.get(0));
            return new String[] { "", endDateTime };
        } else if(dateList.size() == 2) {
            String startDateTime = CONVERT_NATTY_TIME_FORMAT.format(dateList.get(0));
            String endDateTime = CONVERT_NATTY_TIME_FORMAT.format(dateList.get(1));
            return new String[] { startDateTime, endDateTime };
        }
        
        return new String[] { "", "" };
    }
}
{'fraction_non_alphanumeric': 0.14178168130489335, 'fraction_numerical': 0.014742785445420327, 'mean_word_length': 2.3603793466807166, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4885816', 'n_tokens_mistral': 967, 'n_tokens_neox': 929, 'n_words': 226}