Showing posts with label format. Show all posts
Showing posts with label format. Show all posts

Friday, May 01, 2009

Ctrl+Left Shift Vs. Ctrl+Right Shift = Chrome Justifying

I've been battling with Google Chrome for a while because it keeps messing about with my text entry on web forms. The text justification just goes wrong after I do a certain key combination and until today it completely baffled me.

Finally solved it: Ctrl + left Shift = Left justify. Ctrl + right Shift = Right justify.

I don't really understand this even existing as an option, but I also seem to remember reading about it, thinking it was a good idea and turning it on. Now I can't remember how to turn it off, but as soon as I find out I'll post it here! Grrr.

Date Formatting In XSLt

I wanted a date to be changed, essentially a string containing a date time. See my previous post for some good XSLt links, but here's my solution:
<xsl:call-template name="FormatDate">
<xsl:with-param name="DateTimeParam" select="@InvoiceDate"/>
</xsl:call-template>

<xsl:template name="FormatDate">
<!-- expecting datetime example: 2009-04-20T00:00:00 -->
<xsl:param name="DateTimeParam" />


<!-- reformat date param to be easier to use -->
<xsl:variable name="DateTime">
<xsl:value-of select="substring($DateTimeParam,1,10)"/>
</xsl:variable>

<!-- new date format January 20, 2007 -->
<xsl:variable name="year">
<xsl:value-of select="substring-before($DateTime,'-')" />
</xsl:variable>
<xsl:variable name="mo-temp">
<xsl:value-of select="substring-after($DateTime,'-')" />
</xsl:variable>
<xsl:variable name="mo">
<xsl:value-of select="substring-before($mo-temp,'-')" />
</xsl:variable>
<xsl:variable name="day">
<xsl:value-of select="substring-after($mo-temp,'-')" />
</xsl:variable>

<xsl:if test="(string-length($day) &lt; 2)">
<xsl:value-of select="0"/>
</xsl:if>
<xsl:value-of select="$day"/>
<xsl:value-of select="' '"/>
<xsl:choose>
<xsl:when test="$mo = '1' or $mo = '01'">Jan</xsl:when>
<xsl:when test="$mo = '2' or $mo = '02'">Feb</xsl:when>
<xsl:when test="$mo = '3' or $mo = '03'">Mar</xsl:when>
<xsl:when test="$mo = '4' or $mo = '04'">Apr</xsl:when>
<xsl:when test="$mo = '5' or $mo = '05'">May</xsl:when>
<xsl:when test="$mo = '6' or $mo = '06'">Jun</xsl:when>
<xsl:when test="$mo = '7' or $mo = '07'">Jul</xsl:when>
<xsl:when test="$mo = '8' or $mo = '08'">Aug</xsl:when>
<xsl:when test="$mo = '9' or $mo = '09'">Sep</xsl:when>
<xsl:when test="$mo = '10'">Oct</xsl:when>
<xsl:when test="$mo = '11'">Nov</xsl:when>
<xsl:when test="$mo = '12'">Dec</xsl:when>
</xsl:choose>
<xsl:value-of select="' '"/>
<xsl:value-of select="$year"/>
</xsl:template>

Thursday, March 19, 2009

Getting the correct month, no matter the country

Recently I posted about localisation and today need to have a page work out a given month's index value (ie: 1-12) from a string. Because I'm developing the code in the UK and hosting it in the US, the localisation was mucking about with the handling of the DateTime.Parse() interpretation of the date string. I needed the code to handle the parsing as if it was in the UK, no matter where it's hosted.

In short, the answer is from a MSDN article: http://msdn.microsoft.com/en-us/library/bz9tc508.aspx

There are two methods, both easy, to use. The first is in the page's page tag (at the top), where the 'GB' forces things like datetime to use Great Britain formatting:

<%@ Page ... Culture="en-GB" ... %>

The second is in the web.config, again it's the GB:

<system.web>
<globalization uiCulture="en" culture="en-GB" />
...
</system.web>

Now, my code will render properly:

DateTime.Parse("01/" + Int32.Parse(month) + "/2009").ToString("MMMM")

Don't ask why I'm doing that, it's just necessary, is all.

I'm preferring the web.config approach, but it's perfectly valid for the page - just be sure to remember which pages use the setting. Obviously, this can all be set dynamically, but you'll have to read the MSDN pages for how to do that - this is just a reminder for myself and anyone who might run across my pages.