package cn.sunner.sms2calendar;

import android.nfc.Tag;
import android.util.Log;

import java.text.DateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Sunner on 6/29/16.
 *
 * Parse SMS from 12306 (China Railway)
 */
public class N12306Parser extends SMSParser {

    public N12306Parser(String text) {
        super(text);
    }

    @Override
    protected boolean parse() {
        String pattern = ".*[购|签](\\d+)月(\\d+)日(.+[号|铺])([^\\d]+)(\\d+):(\\d+)开。.*";
        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(text);

        if (!m.matches()) {
            return false;
        }

        title = m.group(3);
        location = m.group(4) + "站";   // Append 站 to make it more accurate for maps
        beginTime = new GregorianCalendar(
                Calendar.getInstance().get(Calendar.YEAR),   // Use this year
                Integer.parseInt(m.group(1)) - 1,   // Month. It is 0-based Σ( ° △ °|||)︴
                Integer.parseInt(m.group(2)),   // Day
                Integer.parseInt(m.group(5)),   // Hour
                Integer.parseInt(m.group(6))    // Minute
        );

        // set end time to 1 hour later
        endTime = (Calendar) beginTime.clone();
        endTime.add(Calendar.HOUR, 1);

        return true;
    }
}

@@ -364,16 +364,177 @@
 rser %7B%0A%0A
+    // set end time to 1.5 hour later.%0A    // Why 1.5 hours? Because it is between Hangzhou and Nanjing.%0A    public final int DEFAULT_DURATION_IN_MINUTES = 90;%0A%0A
     publ
@@ -1381,48 +1381,8 @@
 );%0A%0A
-        // set end time to 1 hour later%0A
     
@@ -1458,15 +1458,43 @@
 dar.
-HOUR, 1
+MINUTE, DEFAULT_DURATION_IN_MINUTES
 );%0A%0A

Set default duration to 1.5 hours