Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Added support for "\@" formatting code for dates. #57

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

mpapierski
Copy link
Contributor

@mpapierski mpapierski commented Jul 18, 2018

Description

This change implements very simple \@ formatting code. Examples:

Input Output
y 2018
yy 18
yyyy 18
Y 2018
YY 18
YYYY 2018
M 7
MM 07
MMMM July (based on locale)
d 1
dd 01
dddd Monday (based on locale

The biggest change is that you can now pass custom types, and let the user do the formatting. I.e. pass datetime.datetime and expect user to add formatting code.

There is also default behaviour for certain types which tries to be consistent with Word - i.e. datetime by default would be formatted according to locales etc.

This is still a POC - what do you think on this approach?

Motivation and Context

Let the user do the formatting according to his needs. Your app should be able to pass datetime.datetime objects and expect user to format it according to his needs. It was reported before at least in #13.

How Has This Been Tested?

Added unit tests for eval stage.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

This supports only dates at this moment.
Even if user won't specify '\*', or would strip code to bare minimum
i.e. "MERGEFIELD foo" (which is valid according to Word), it would still
evaluate with default formats. This default format is dependent on
locale settings which seems to be consistent with what Word is doing.
Formatting "None" (called from MailMerge.write) would cause errors. In
such cases it should always evaluate to '' (empty string), and any other
type that is not a date or time would evaluate to string representation.
@Bouke
Copy link
Owner

Bouke commented Oct 9, 2019

I think this looks like a nice addition. I haven't gotten any use for this library myself, and haven't touched the code in a while. With that in mind, I think the code looks good.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants