Editorial Workflows

TaskPaper Past and Today Date Regex

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: This workflow contains python scripts that generate regex for matching TaskPaper date tags containing past dates and/or today's date, like @start(2016-03-25).

The default tag to match is @start(). You can change the options in the python scripts to match other tags like @due() instead of @start().

Version 2: Better handles first day of the month.

Shared by: @pronetobits

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Run Python Script ?
Source Code
#coding: utf-8
import workflow
import time

action_in = workflow.get_input()

### SCRIPT DESCRIPTION ###

# This script generates a regex that matches entire lines of text that contain date tags for all dates before today in the format of tag(2016-01-01) (i.e., four digit year - two digit month - two digit day)


### SCRIPT CUSTOMIZATION ###

# The default date tag for this script is "start" date tags
# Customize this script by substituting a different date tag below such as "due" or "added"
tag = "start"


### BEGIN SCRIPT ###

year = time.strftime('%Y')
month = time.strftime('%m')
day = time.strftime('%d')

def varyYear(year):
 	doubleDigits= int(year) - 2000
	if (int(doubleDigits) < 10):
		singleDigit = int(doubleDigits) - 1
		return "((200[0-" + str(singleDigit) + "])"
	elif (int(doubleDigits) < 11):
		return "(((200[1-9]))"
	elif (int(doubleDigits) < 20):
		highest = int(doubleDigits) - 10
		theRange = ''.join(str(x) for x in xrange(0,(highest)))
		return "(((200[1-9])|(201[" + theRange + "]))"
	elif (int(doubleDigits) < 21):
		return "(((20[01][1-9]))"
	elif (int(doubleDigits) < 30):
		highest = int(doubleDigits) - 20
		theRange = ''.join(str(x) for x in xrange(0,(highest)))
		return "(((20[01][1-9])|(202[" + theRange + "]))"

def varyMonth(month):
	if (int(month) < 2):
		return "(0[0])"
	elif (int(month) < 10):
		return "(0[1-" + str((int(month) - 1)) + "])"
	elif (int(month) < 11):
		return "0[1-9]"
	elif (int(month) < 13):
		highest = int(month) - 10
		theRange = ''.join(str(x) for x in xrange(0,(highest)))
		return "(0[1-9]|1[" + theRange + "])"

def varyDay(day):
	if (int(day) < 2):
		return "(0[0])"
	elif (int(day) < 10):
		return "(0[1-" + str(int(day)) + "])"
	elif (int(day) < 11):
		return "0[1-9]"
	elif (int(day) < 20):
		highest = int(day) - 10
		theRange = ''.join(str(x) for x in xrange(0,(highest)))
		return "(0[1-9]|1[" + theRange + "])"
	elif (int(day) < 21):
		return "(0[1-9]|1[0-9])"
	elif (int(day) < 30):
		highest = int(day) - 20
		theRange = ''.join(str(x) for x in xrange(0,(highest)))
		return "([01][1-9]|2[" + theRange + "])"
	elif (int(day) < 31):
		return "(0[1-9]|[12][0-9])"
	elif (int(day) < 32):
		highest = int(day) - 30
		theRange = ''.join(str(x) for x in xrange(0,(highest)))
		return "([012][1-9]|3[" + theRange + "])"
		
regex1 = varyYear(year) + "[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01]))"
regex2 = str(year) + "[- /.]" + varyMonth(month) + "[- /.](0[1-9]|[12][0-9]|3[01])"
regex3 = str(year) + "[- /.]" + str(month).zfill(2)  + "[- /.]" + varyDay(day)

#TODO: Generate the output...
action_out = ".*@" + tag + "\(" + regex1 + "\).*|.*@" + tag + "\(" + regex2 + "\).*|.*@" + tag + "\(" + regex3 + "\).*"

workflow.set_output(action_out)
Set Variable ?
Variable Name
pastDates
Value
Input
Run Python Script ?
Source Code
#coding: utf-8
import workflow
import time

action_in = workflow.get_input()

#coding: utf-8

import time

### SCRIPT DESCRIPTION ###

# This script generates a regex that matches entire lines of text that contain date tags for today's date in the format of tag(2016-01-01) (i.e., four digit year - two digit month - two digit day)

### SCRIPT CUSTOMIZATION ###

# The default date tag for this script is "start" date tags
# Customize this script by substituting a different date tag below such as "due" or "added"
tag = "start"


### BEGIN SCRIPT ###
year = time.strftime('%Y')
month = time.strftime('%m')
day = time.strftime('%d')

regex = year + "-" + month + "-" + day

#TODO: Generate the output...
action_out = ".*@" + tag + "\(" + regex + "\).*"

workflow.set_output(action_out)
Set Variable ?
Variable Name
todayDate
Value
Input
Set Variable ?
Variable Name
pastDatesAndToday
Value
pastDates|todayDate