Medjool: Ruby Date Parsing With Context

The Date.parse method in Ruby on Rails is a really useful little function. Yes, it probably comes with huge overheads, and no, obviously you wouldn’t want to be using it in performance-critical code. But every now and again it’s really ace.

Except for one thing: you can’t provide it with any context whatsoever. “Tuesday” always means next Tuesday, no matter what. “1st” always means 1st of the current month, come what may.

When building the “Quick Import” feature of, I needed a little more flexibility than that. The goal was to allow churches to copy & paste their prayer points from their weekly notice sheet, and for the site to just “know” what each date meant. So, for example, if you’ve just parsed a prayer point for “Tuesday”, odds are that when you come across a prayer point for a “Wednesday”, that almost certainly means the day after the Tuesday that you just processed. Date.parse can’t cope with that. That’s why I built Medjool – all the simplicity and flexibility of Date.parse, just with a little more context.

p ={:now => "2013-09-31".to_date})
p.parse("1st") => 1st October 2013
p.parse("3rd") => 3rd October 2013
p.parse("1st") => 1st November 2013
p.parse("Wednesday") => Wednesday 6th November 2013

I looked into doing this with Chronic, but Chronic is really geared towards Time processing rather than simply Date processing. It also seems pretty buggy when it comes to dates, and gives different results depending on the exact input date format. Medjool, by contrast, ALWAYS delegates parsing to Date.parse, it just then sometimes plays around with the result it gets back to make sure it’s after the previously parsed date, if there was any ambiguity.

The Mixed Blessing of a New iOS Version

As a independent developer of a small app targeting a niche audience, a new version of iOS is a mixed blessing. It is always accompanied by some fantastic new features which will inevitably make my app work better – but at the same time, there are costs associated with upgrading to make use of them. Finding the time to redesign an app from scratch to work nicely with iOS7 is no mean feat when you have a full time job as well. And then there’s that age old dilemma: do I drop support for older iOS versions and devices in order to make the most of the new features? Apple has a way of always making this decision more urgent than it would otherwise be: when the iPhone 5 came out with it’s 4″ screen, you could only target that if you were running a version of XCode that no longer supported the older armv6 devices like the original iPods and iPhones; likewise, you can’t compile arm64 code for the new iPhone 5S if your app still targets iOS5, like mine does.

But according to The Next Web, Apple has made a small but significant change to the App Store which would significantly reduce the stress involved in these decisions: users of outdated iOS versions will apparently now get the option to download older versions of an app which still supports their hardware. This has the potential to be HUGE, and we could well see a surge in developers targeting the latest features since they no longer have to worry about all of the users who will no longer be able to download their app as a result.

Well played Apple.

Update: Simon Maddox has pointed out that this can also prove to be a support nightmare, since out-of-date versions that don’t play nicely with your current APIs are now hanging around forever. But to some extent, this would have been the case anyway – I still have plenty of out-of-date apps running on my iOS5 iPad.

Why we’re wrong to fear opposition

Opposition in the book of Acts

I’ve just recently finished reading reading my way through the book of Acts. A big theme of the book struck me afresh this time, which I’m not sure I’d really noticed in quite the same way before.

Acts is a book filled with examples of opposition to the gospel. The chief priests and religious leaders oppose the early disciples and try to stop them preaching. The Jewish people largely seem to reject their message, often hounding them out of their synagogues. The people of Ephesus even start a riot because they’re so offended by Paul and his gospel. And yet time and time again, we see that the disciples are unfazed by these responses. Indeed, in Chapter 5:41 we read that “the apostles left the Sanhedrin, rejoicing because they had been counted worthy of suffering disgrace for the Name.” They rejoiced that they got to suffer on behalf on Jesus. What on earth is going on?

Opposition is God’s plan

Right near the start of the book and right at the end of the book we have a couple of quotes from the Old Testament that I think help explain this a little. In Chapter 4 we have a quote from Psalm 2:

“Why do the nations rage
and the peoples plot in vain?
The kings of the earth rise up
and the rulers band together
against the Lord
and against his anointed one”

In Psalm 2 we see the powerful ones of the earth attempting to rise up against God, and what does God do? He laughs. Even the mightiest people on the planet are like puny ants trying to start a fight with the Creator of the Universe, and it is laughable. Peter goes on to say “Herod and Pontius Pilate met together with the Gentiles and the people of Israel in this city to conspire against your holy servant Jesus, whom you anointed. They did what your power and will had decided beforehand should happen.” When the kings of the earth conspire against God, all they end up achieving is bringing God’s purposes to pass.

Then at the end of the book, Paul gives an extended quote from Isaiah 6:

“Go to this people, and say,
You will indeed hear but never understand,
and you will indeed see but never perceive.
For this people’s heart has grown dull,
and with their ears they can barely hear,
and their eyes they have closed;
lest they should see with their eyes
and hear with their ears
and understand with their heart
and turn, and I would heal them.”

In other words, God knew that the Jewish people would reject the message of the crucified Messiah Jesus. It wasn’t a surprise to him – it was in his plan all along. Paul concludes: “Therefore I want you to know that God’s salvation has been sent to the Gentiles, and they will listen!” This rejection that we’ve been seeing right through the book of Acts is all part of the master plan to fulfil Jesus’ promise to take the gospel to all Jerusalem, Judea & Samaria, and to the ends of the earth.

Not fearing opposition

This encourages me. What is the number one reason I don’t share the gospel with more people? It’s got to be the fear of rejection. But the book of Acts tells me that when opposition happens, God expects it, and indeed God uses it to further his purposes. The Apostle Paul knew with certainty that if he went to Jerusalem, he would be bound hand and foot. But did that stop him going? No! He was compelled to preach the gospel whatever the cost – sometimes even because he knew that the opposition he received would only help him preach the gospel in even more places. When he does finally get arrested in Jerusalem, it allows him the opportunity to go to Rome to speak the gospel before the Emperor himself.

So don’t let the fear of opposition stop you from speaking up about Jesus. Know with conviction that God is in charge, and God is bigger than any opposition we might face. His will is that the gospel will go out to all the earth, and it’s a privilege to get to be part of that work.

Getting more out of PrayerMate with Dropbox

Actually… getting more *IN* to PrayerMate

For many people, one of the things that stops them using PrayerMate more is the challenge of actually getting their prayer points into the app. Typing on a mobile is slow and cumbersome, and perhaps you already have lots of prayers in another system that you wouldn’t want to have to enter all over again.

With the newly released PrayerMate 3.1.0, getting your data into PrayerMate is easier than ever, with a little help from the wonderful Dropbox. Here are three ways that Dropbox can help you.

1. Migrations and backup

One key use of Dropbox is to allow you to backup your PrayerMate data, so that you can import it again later in the case of a lost or reset phone, or migrating it to a second device. Under the app’s main “Settings” menu within PrayerMate (accessible whilst praying), hit the “Export data” / “Export to Dropbox” button. Depending on your device, you may then be given the option to export “via Dropbox” or “via another app” – try “via Dropbox” and if that doesn’t work then try via another app instead (and if you have the Dropbox app installed, this should even come up as one of the options). The first time you use it you’ll be prompted for your Dropbox credentials, and then it will save your entire database into a special folder within your Dropbox called “Apps/PrayerMate” as a .json file with today’s date. You can then import this again later, or on another device, using the “Import from Dropbox” button.

When you import, it will look for existing categories and subjects with the same name and reuse them where possible, so in theory you could import more than once without causing duplication. However, it is not going to prove a very satisfying experience trying to use this to continually keep two devices in sync with each other. I’m working on a proper solution to the syncing issue as a matter of priority.

2. Importing new data

dropbox_import Whilst the first point was all about moving existing data around, Dropbox is also very useful for getting completely new data into PrayerMate. If you place any text file with a “.txt” extension in your “Apps/PrayerMate” Dropbox folder, then you can use that to create a new subject. Hit the “Import data” button under the app’s main “Settings” page, and you should see your .txt file listed. When you tap it, it will then begin the process of creating a new subject with the same name as your .txt file (underscores ‘_’ will be replaced with spaces) and the contents of the text file will be used to populate the description.

In PrayerMate 3.1.0 (iOS only) there’s also now an “Import all” button. Hit this, then choose one of your categories, and it will load in all of the .txt files in the current directory and create one subject for each. You can create sub-folders within your Dropbox, one per category, if you want a little more control – then just use “Import all” within specific sub-folders.

3. Adding PDF attachments

If you’re anything like me, you’re constantly being sent prayer letters as PDFs that you read once then promptly forget. Now, if you add them to the “Apps/PrayerMate” folder within your Dropbox, when you hit “Import data” you will see those PDF files listed with a paperclip icon. Once you select the file you want, you’ll be asked to pick one of your subjects, and it will attach that PDF file to that subject. When you’re praying you’ll then see a “PDF” button which you can tap to view it fullscreen.

Aside: Dropbox Android bug

At the time of writing, there is a bug in Dropbox for Android that affects certain people which may stop you authorising PrayerMate to access your Dropbox: the “allow” button is showing as frozen for some people. Dropbox is working on a fix for this, but in the mean time, if this affects you they suggest this:

I have talked with the Dropbox engineers and this issue arises whenever another third party app has an overlay screen on top of the Dropbox app. I would recommend telling your users to disable any other apps that overlay their Android screen so that they can then click through the Dropbox authorization screen.

I hope that clears things up and sorry for any inconvenience this caused.

Sign up to Dropbox here or download PrayerMate here.