Jump to content

Recommended Posts

Posted

Whilst choosing a Calendar/Date picker for a webapp I'm writing, I stumbled upon this nicity.

 

Granted, it's not as powerful as ASP.NET AJAX's Calendar picker, it's a lot simpler and easier to work with, and doesn't involve gutting your project to get ASP.NET AJAX to work.

 

...plus it fits in with my Mootools libraries (strongly recommended if you've already written Adapters for all the controls already).

 

My app uses the user's selected culture for every occasion it handles dates, which is useful. So date filtering and dates in forms all use the user's selected ShortDateFormat string.

 

...but shock-horror! The picker I've selected can only parse PHP's date format strings. For the record, PHP's date strings are just as flexible as .NET's, but use one character per token, making them easier to parse.

 

That said, I took it upon myself to write a converter class so I can use the current user's format settings with this calendar picker.

 

...I get it to use it by writing the current culture's date format string in a block on the page itself.

 

Anyway, voila (and thanks to Maurits with devising the algo to work with edge conditions).

 

using System;

using System.Collections.Generic;

using System.Text;

 

using DictSS = System.Collections.Generic.Dictionary;

 

namespace W3b.MortCal {

 

public static class DateFormatConverter {

 

public static String ToPhPString(String s) {

 

// tokenize string

 

// split the string into tokens whereever there's a character delta

// or where the string is

 

List tokens = new List();

 

StringBuilder currentToken = new StringBuilder();

for(int i=0;i

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...