Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public CharSequence filter(CharSequence source, int start, int end, Spanned dest
}

private CharSequence autoIndent(CharSequence source) {
return source + TodoTxtTask.DATEF_YYYY_MM_DD.format(new Date()) + " ";
return source + TodoTxtTask.getDateFormat().format(new Date()) + " ";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import net.gsantner.markor.frontend.textview.TextViewUtils;
import net.gsantner.opoc.format.GsTextUtils;
import net.gsantner.markor.ApplicationObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand All @@ -30,12 +31,29 @@
public class TodoTxtTask {

//
// Static memebers
// Static members - date format helpers, regex generators & constants
//

public static final SimpleDateFormat DATEF_YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);
public static final int DATEF_YYYY_MM_DD_LEN = "yyyy-MM-dd".length();
public static final String PT_DATE = "\\d{4}-\\d{2}-\\d{2}";

/**
* Returns a SimpleDateFormat for the configured todo date format.
* Falls back to {@link #DATE_FORMAT} if settings are not available or the configured pattern is invalid.
* Note: This does not cache the SimpleDateFormat instance because the pattern may change at runtime.
*/
public static SimpleDateFormat getDateFormat() {
final String fmt = ApplicationObject.settings() != null ? ApplicationObject.settings().getTodoDateFormat() : "yyyy-MM-dd";

try {
return new SimpleDateFormat(fmt, Locale.ROOT);
} catch (IllegalArgumentException e) {
// Fallback: return a default format instead of throwing
return DATEF_YYYY_MM_DD;
}
}

public static final String PT_DATE = "\\d{4}-\\d{2}-\\d{2}(?:[ T]\\d{2}:\\d{2}(?::\\d{2})?)?";
public static final Pattern PATTERN_PROJECTS = Pattern.compile("(?:^|\\s)(?:\\++)(\\S+)");
public static final Pattern PATTERN_CONTEXTS = Pattern.compile("(?:^|\\s)(?:\\@+)(\\S+)");
public static final Pattern PATTERN_DONE = Pattern.compile("(?m)(^[Xx]) (.*)$");
Expand All @@ -61,7 +79,7 @@ public enum TodoDueState {
}

public static String getToday() {
return DATEF_YYYY_MM_DD.format(new Date());
return getDateFormat().format(new Date());
}

public static List<TodoTxtTask> getTasks(final CharSequence text, final int[] sel) {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/net/gsantner/markor/model/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ public boolean isTodoAddCompletionDateEnabled() {
return getBool(R.string.pref_key__todotxt__add_completion_date_for_todos, true);
}

public String getTodoDateFormat() {
return getString(R.string.pref_key__todotxt__set_date_format, "yyyy-MM-dd");
}

public boolean isAppCurrentVersionFirstStart(boolean doSet) {
int value = getInt(R.string.pref_key__app_first_start_current_version, -1);
if (doSet) {
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@
<item translatable="false">+</item>
</string-array>

<string-array name="pref_arrdisp__todo_date_format" translatable="false">
<item translatable="false">@string/todo_date_format_year_month_day</item>
<item translatable="false">@string/todo_date_format_year_month_day_hour_minute</item>
<item translatable="false">@string/todo_date_format_year_month_day_hour_minute_second</item>
</string-array>

<string-array name="pref_arrkeys__todo_date_format" translatable="false">
<item translatable="false">yyyy-MM-dd</item>
<item translatable="false">yyyy-MM-dd HH:mm</item>
<item translatable="false">yyyy-MM-dd HH:mm:ss</item>
</string-array>

<string-array name="pref_arrdisp__markdown_toc" translatable="false">
<item translatable="false">@string/heading_1</item>
<item translatable="false">@string/heading_2</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/string-not_translatable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pref_key__editor_tab_to_indent" translatable="false">pref_key__editor_tab_to_indent</string>
<string name="hidden_password" translatable="false">****</string>
<string name="pref_key__todotxt__additional_projects_contexts" translatable="false">"pref_key__todotxt__additional_projects_contexts"</string>
<string name="pref_key__todotxt__set_date_format" translatable="false">"pref_key__todotxt__set_date_format"</string>
<string name="pref_key__todotxt__due_date_offset" translatable="false">pref_key__todotxt_due_date_offset</string>
<string name="action_format_keyvalue" translatable="false">action_format_keyvalue</string>
<string name="action_format_plaintext" translatable="false">action_format_plaintext</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="code_block">Code block</string>
<string name="add_completion_date">Add completion date</string>
<string name="add_completion_date_for_todos_when_marking_them_as_done">Add completion date for todos when marking them as done</string>
<string name="set_date_format">Set date format</string>
<string name="set_date_format_used_in_todo_tasks">Set date format used in todo tasks</string>
<string name="todo_date_format_year_month_day">yyyy-MM-dd (2026-12-31)</string>
<string name="todo_date_format_year_month_day_hour_minute">yyyy-MM-dd HH:mm (2026-12-31 14:30)</string>
<string name="todo_date_format_year_month_day_hour_minute_second">yyyy-MM-dd HH:mm:ss (2026-12-31 14:30:45)</string>
<string name="file_description_format">File description format</string>
<string name="file_description_format_dialog">Format for the description under each file in the file browser. Follows Android\'s SimpleDateFormat rules, with the addition of FS for showing file size. Leave blank to use the default format for your locale.\n\nExample input:\nFS yyyy MMM dd hh:mm:ss aa\nOutput format:\n30KB 2020 Mar 20 11:24:52 PM</string>
<string name="loading_default_value">Loading default value</string>
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/xml/preferences_master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,15 @@
android:key="@string/pref_key__todotxt__add_completion_date_for_todos"
android:summary="@string/add_completion_date_for_todos_when_marking_them_as_done"
android:title="@string/add_completion_date" />
<ListPreference
android:defaultValue="yyyy-MM-dd"
android:dialogTitle="@string/theme"
android:entries="@array/pref_arrdisp__todo_date_format"
android:entryValues="@array/pref_arrkeys__todo_date_format"
android:icon="@drawable/ic_list_black_24dp"
android:key="@string/pref_key__todotxt__set_date_format"
android:summary="@string/set_date_format_used_in_todo_tasks"
android:title="@string/set_date_format" />
<CheckBoxPreference
android:defaultValue="true"
android:icon="@drawable/ic_add_white_24dp"
Expand Down