NewsBot
1
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
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