We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Number To Date

Development and Programming

Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

The attached add-on files may be out of date. Please visit Devot-ee for the latest versions.

Hi,

I would like to present to your attention a new plugin - Number To Date.

There is also Number To Date extension.

The purpose of this plugin is to assist in ordering of entries which have titles containing numbers. Order of such entries should match numerical values of numbers in titles, as here: “§ 1”, “§ 2”, “§ 3”, … “§ 10”, “§ 11”, “§ 12”, etc. Or as here: …, “Article 528”, “Articles 529-530”, “Article 531”, “Articles 531-533”, “Articles 533-535” etc.

It is not possible to achieve such order using ExpressionEngine’s ordering of entries by title. Using ordering of entries by title you will get this order instead: §1, §11, §12, §13, … §2, §21, etc.

If real posting date does not matter, needed ordering of entries can be achieved by setting posting dates. Number To Date plugin automatizes process of calculating dates for such entries. It takes as an input a string (which can be title, or url_title, or some other string) containing one or two numbers (the second must be bigger than the first at least by 1) in the range between 1 and 9999, and outputs a date formatted for use in ExpressionEngine’s PUBLISH page.

PARAMETERS:

1) string - Required. Allows you to specify string containing one or two integers.

2) invalid_input - Optional. Accepts two values: “alert” and “silence”. Default value is “silence”. If the value is “alert”, then in cases when “string” parameter’s value is invalid plugin exits and PHP alert is being shown; if the value is “silence”, then in cases when “string” parameter’s value is invalid no alert is being shown. Set this parameter to “alert” for development, and to “silence” - for deployment.

VARIABLE:

1) {computed_date} - outputs id number of parent category.

EXAMPLES OF USAGE:
{exp:number_to_date string="article_14" invalid_input="alert"}
  {computed_date}
  {/exp:number_to_date}

This code will output: 1990-01-02 04:00 AM

{exp:number_to_date string="articles_15_17" invalid_input="alert"}
  {computed_date}
  {/exp:number_to_date}

This code will output: 1990-01-02 05:02 AM

ILLEGAL INPUT:

1) “string” parameter’s value contains more than two numbers.

2) Second number included in “string” parameter’s value is equal to or lesser than the first number.

3) “string” parameter’s value does not contain any number.

4) Number contained in “string” parameter’s value is zero.

5) Number contained in “string” parameter’s value has leading zero.

I use this plugin in situations when titles of yet to be published entries are standard, are known in advance and contain numbers. Using this plugin I am able publish a list of titles together with dates to be set. It is convenient for content authors since they need not calculate the date by themselves; instead they can simply copy-paste the date calculated by plugin. Then ExpressionEngine orders entries by their fictitious dates.

For the situations when titles are standard, contain numbers, but cannot be known in advance, I have a javascript version of the same script here.

Continued in the next post

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

In order to understand how plugin works three cases should be taken into consideration.

Case A. String, which is the value of “string” parameter contains one integer. The plugin will produce a date which is later than any date it outputs for any string containing one lesser number and earlier than any date it outputs for any any string containing one bigger number. E.g if string contains integer “108” the plugin will output a date which is later than the date it outputs for string containing integer “107” and earlier than the date it outputs for string containing integer “109”.

Case B. String contains two integers, and the second is bigger than the first at least by 1 but no more than 59. E.g. string contains integers “210” and “240”. The plugin will produce a date which is (a) later than the date it outputs for string containing one integer “210”, (b) later than any date it outputs for string containing two integers, one of which is “210” and the second is in the range between 211 and 239, and (c) earlier than any date it outputs for string containing two integers, one of which is “210” and the second is in the range between 241 and 269, and (d) earlier than the date it outputs for string containing one integer “211”.

Case C. String contains two integers, and the second is bigger than the first by more than 59. E.g. string contains integers “321” and “398”. The plugin will produce a date which is the same as the date it will produce for a string containing the integer “321” and an integer bigger than this by 59, that is, the same date as for string containing integers “321” and “380”.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.