diff --git a/.gitignore b/.gitignore index 04ae7b3..776e1b0 100644 --- a/.gitignore +++ b/.gitignore @@ -22,185 +22,5 @@ bld/ [Bb]in/ [Oo]bj/ -# Visual Studio 2015 cache/options directory -.vs/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# DNX -project.lock.json -artifacts/ - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opensdf -*.sdf -*.cachefile - -# Visual Studio profiler -*.psess -*.vsp -*.vspx - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config - -# Windows Azure Build Output -csx/ -*.build.csdef - -# Windows Store app package directory -AppPackages/ - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -[Ss]tyle[Cc]op.* -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.pfx -*.publishsettings -node_modules/ -orleans.codegen.cs - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -*.mdf -*.ldf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings - -# Microsoft Fakes -FakesAssemblies/ - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt \ No newline at end of file +# Library +[Ll]ib/ \ No newline at end of file diff --git a/blogger.toc.csproj b/blogger.toc.csproj index e9ed07b..fbf31e0 100644 --- a/blogger.toc.csproj +++ b/blogger.toc.csproj @@ -87,22 +87,25 @@ - - - - - - - + + + + + + + - - - - + + + + + + + @@ -165,7 +168,8 @@ - $(ProjectDir)build.bat + $(ProjectDir)createDepsJs.bat +$(ProjectDir)build.bat + @@ -16,6 +16,14 @@

No Compile Mode

printby: 'label.contentsorder', thumbnail: { enabled: false + }, + published: { + enabled: true, + format: 'yyyy/MM/dd' + }, + updated: { + enabled: true, + format: 'yyyy/MM/dd' } }; diff --git a/src/blogger/toc/contract.js b/src/blogger/toc/contract.js index 654a9b5..db8a369 100644 --- a/src/blogger/toc/contract.js +++ b/src/blogger/toc/contract.js @@ -125,11 +125,19 @@ var contract = { var POSTSTOC_SETTINGS = { blogURL: '', maxResults: Infinity, - style: '', orderby: '', printby: '', + locale: '', thumbnail: { enabled: false, noImageURL: '' + }, + published: { + enabled: false, + format: '' + }, + updated: { + enabled: false, + format: '' } }; \ No newline at end of file diff --git a/src/blogger/toc/printer/entry.js b/src/blogger/toc/printer/entry.js index e80f93c..6779ac8 100644 --- a/src/blogger/toc/printer/entry.js +++ b/src/blogger/toc/printer/entry.js @@ -1,5 +1,7 @@ goog.provide('garafu.blogger.toc.printer.Entry'); +goog.require('garafu.date.W3CDTF'); + @@ -62,7 +64,7 @@ garafu.blogger.toc.printer.Entry.prototype.initialize = function () { var updated = document.createElement('span'); var thumbnail = document.createElement('span'); var title = document.createElement('a'); - var img; + var datetime, text, img; // Create thumbnail if (settings.thumbnail.enabled) { @@ -71,12 +73,20 @@ garafu.blogger.toc.printer.Entry.prototype.initialize = function () { } // Create published date - published.appendChild(document.createTextNode(entry.published.$t)); - published.className = 'poststoc-published'; + if (settings.published.enabled) { + datetime = garafu.date.W3CDTF.parse(entry.published.$t); + text = settings.published.format.format(datetime); + published.appendChild(document.createTextNode(text)); + published.className = 'poststoc-published'; + } // Create update date - updated.appendChild(document.createTextNode(entry.updated.$t)); - updated.className = 'poststoc-updated'; + if (settings.updated.enabled) { + datetime = garafu.date.W3CDTF.parse(entry.updated.$t); + text = settings.updated.format.format(datetime); + updated.appendChild(document.createTextNode(text)); + updated.className = 'poststoc-updated'; + } // Create title title.appendChild(document.createTextNode(entry.title.$t)); @@ -87,8 +97,12 @@ garafu.blogger.toc.printer.Entry.prototype.initialize = function () { if (settings.thumbnail.enabled) { container.appendChild(thumbnail); } - container.appendChild(published); - container.appendChild(updated); + if (settings.published.enabled) { + container.appendChild(published); + } + if (settings.updated.enabled) { + container.appendChild(updated); + } container.appendChild(title); container.className = 'poststoc-entry'; diff --git a/src/blogger/toc/settings.js b/src/blogger/toc/settings.js index 09c3a85..d50e306 100644 --- a/src/blogger/toc/settings.js +++ b/src/blogger/toc/settings.js @@ -1,5 +1,7 @@ goog.provide('garafu.blogger.toc.Settings'); +goog.require('garafu.i18n.DateTimeFormat'); + @@ -12,21 +14,35 @@ goog.provide('garafu.blogger.toc.Settings'); * @constructor */ garafu.blogger.toc.Settings = function () { + var defaultSettings; // Set default settings. - var defaultSettings = { + defaultSettings = { blogURL: 'garafu.blogspot.jp', maxResults: Infinity, orderby: 'published', printby: 'label', + locale: 'ja-jp', thumbnail: { enabled: false, noImageURL: 'http://garafu.github.io/blogger.toc/release/0.0.5/noimage.png' + }, + published: { + enabled: false, + format: 'yyyy/MM/dd HH:mm:ss' + }, + updated: { + enabled: false, + format: 'yyyy/MM/dd HH:mm:ss' } }; // Apply user settings or default settings. this.merge(this, POSTSTOC_SETTINGS, defaultSettings); + + // Set date time formatter. + this.published.format = new garafu.i18n.DateTimeFormat(this.published.format, this.locale); + this.updated.format = new garafu.i18n.DateTimeFormat(this.updated.format, this.locale); }; diff --git a/src/date/W3CDTF.js b/src/date/W3CDTF.js index 2896201..c358ba5 100644 --- a/src/date/W3CDTF.js +++ b/src/date/W3CDTF.js @@ -1,5 +1,7 @@ goog.provide('garafu.date.W3CDTF'); +goog.require('garafu.string'); + @@ -9,16 +11,31 @@ goog.provide('garafu.date.W3CDTF'); * @private * @type {RegExp} */ -garafu.date.W3CDTF.regexp = new RegExp("^(\\d{4})-?(\\d{2})?-?(\\d{2})?T?(\\d{2})?:?(\\d{2})?:?(\\d{2})?(\\.\\d+)?(\\+|-|Z)?(\\d{2})?:?(\\d{2})?$"); +garafu.date.W3CDTF.regexp = /^(\d{4})-?(\d{2})?-?(\d{2})?T?(\d{2})?:?(\d{2})?:?(\d{2})?(\.\d+)?(\+|-|Z)?(\d{2})?:?(\d{2})?$/; +/** +* W3CDTF format type enumeration. +* +* @public +*/ +garafu.date.W3CDTF.FormatType = { + YYYY: 1, + YYYYMM: 2, + YYYYMMDD: 3, + YYYYMMDD_hhmmTZD: 4, + YYYYMMDD_hhmmssTZD: 5, + YYYYMMDD_hhmmsssTZD: 6 +}; /** * Convert W3C-DTF string to Date object. * +* @public +* @static * @param {string} text W3C-DTF string. -* @return {Date} Date object. +* @return {Date} Date object. */ garafu.date.W3CDTF.parse = function (text) { var splitted; @@ -61,3 +78,85 @@ garafu.date.W3CDTF.parse = function (text) { return date; }; + +/** +* Parse to string from Date object. +* +* @public +* @static +* @param {Date} date Date object. +* @return {string} W3C-DTF format string. +*/ +garafu.date.W3CDTF.stringify = function (date, formatType) { + var year = date.getUTCFullYear(); + var month = date.getUTCMonth() + 1; + var day = date.getUTCDate(); + var hour = date.getUTCHours(); + var minute = date.getUTCMinutes(); + var second = date.getUTCSeconds(); + var millisecond = Math.round(date.getUTCMilliseconds() / 100.0); + var text = ''; + + // Concat string to the W3C-DTF type of YYYY-MM-DDThh:mm:ss.sTZD. + switch (formatType) { + case garafu.date.W3CDTF.FormatType.YYYY: + text += year; + break; + case garafu.date.W3CDTF.FormatType.YYYYMM: + text += year; + text += '-'; + text += garafu.string.paddingNumber(month, 2); + break; + case garafu.date.W3CDTF.FormatType.YYYYMMDD: + text += year; + text += '-'; + text += garafu.string.paddingNumber(month, 2); + text += '-'; + text += garafu.string.paddingNumber(day, 2); + break; + case garafu.date.W3CDTF.FormatType.YYYYMMDD_hhmmTZD: + text += year; + text += '-'; + text += garafu.string.paddingNumber(month, 2); + text += '-'; + text += garafu.string.paddingNumber(day, 2); + text += 'T'; + text += garafu.string.paddingNumber(hour, 2); + text += ':'; + text += garafu.string.paddingNumber(minute, 2); + text += 'Z'; + break; + case garafu.date.W3CDTF.FormatType.YYYYMMDD_hhmmssTZD: + text += year; + text += '-'; + text += garafu.string.paddingNumber(month, 2); + text += '-'; + text += garafu.string.paddingNumber(day, 2); + text += 'T'; + text += garafu.string.paddingNumber(hour, 2); + text += ':'; + text += garafu.string.paddingNumber(minute, 2); + text += ':'; + text += garafu.string.paddingNumber(second, 2); + text += 'Z'; + break; + default: + text += year; + text += '-'; + text += garafu.string.paddingNumber(month, 2); + text += '-'; + text += garafu.string.paddingNumber(day, 2); + text += 'T'; + text += garafu.string.paddingNumber(hour, 2); + text += ':'; + text += garafu.string.paddingNumber(minute, 2); + text += ':'; + text += garafu.string.paddingNumber(second, 2); + text += '.'; + text += millisecond; + text += 'Z'; // timezone; + break; + } + + return text; +}; diff --git a/src/deps.js b/src/deps.js index 5ec2009..f6ec37c 100644 --- a/src/deps.js +++ b/src/deps.js @@ -1,18 +1,21 @@ -// This file was autogenerated by C:\Users\Owner\WorkSpace\GitHub\blogger.toc\lib\closure-library\closure\bin\build\depswriter.py. +// This file was autogenerated by D:\Work\GitHub\blogger.toc\lib\closure-library\closure\bin\build\depswriter.py. // Please do not edit. goog.addDependency('../../../../src/blogger/toc/main.js', ['garafu.blogger.toc.Main'], ['garafu.blogger.toc.Settings', 'garafu.blogger.toc.printer.LabelContentsOrderPrinter', 'garafu.blogger.toc.printer.LabelNameOrderPrinter', 'garafu.blogger.toc.printer.LabelPrinter', 'garafu.blogger.toc.printer.TitlePrinter', 'garafu.blogger.toc.sorter.PublishedDateSorter', 'garafu.blogger.toc.sorter.TitleNameSorter', 'garafu.blogger.toc.sorter.UpdatedDateSorter', 'garafu.date.W3CDTF', 'garafu.dom', 'garafu.events']); -goog.addDependency('../../../../src/blogger/toc/printer/abstractprinter.js', ['garafu.blogger.toc.printer.AbstractPrinter'], []); -goog.addDependency('../../../../src/blogger/toc/printer/category.js', ['garafu.blogger.toc.printer.Category'], []); -goog.addDependency('../../../../src/blogger/toc/printer/entry.js', ['garafu.blogger.toc.printer.Entry'], []); -goog.addDependency('../../../../src/blogger/toc/printer/labelcontentsorderprinter.js', ['garafu.blogger.toc.printer.LabelContentsOrderPrinter'], ['garafu.blogger.toc.printer.LabelPrinter']); -goog.addDependency('../../../../src/blogger/toc/printer/labelnameorderprinter.js', ['garafu.blogger.toc.printer.LabelNameOrderPrinter'], ['garafu.blogger.toc.printer.LabelPrinter']); -goog.addDependency('../../../../src/blogger/toc/printer/labelprinter.js', ['garafu.blogger.toc.printer.LabelPrinter'], ['garafu.blogger.toc.printer.AbstractPrinter', 'garafu.blogger.toc.printer.Category', 'garafu.blogger.toc.printer.Entry']); -goog.addDependency('../../../../src/blogger/toc/printer/titleprinter.js', ['garafu.blogger.toc.printer.TitlePrinter'], ['garafu.blogger.toc.printer.AbstractPrinter']); -goog.addDependency('../../../../src/blogger/toc/settings.js', ['garafu.blogger.toc.Settings'], []); -goog.addDependency('../../../../src/blogger/toc/sorter/abstractsorter.js', ['garafu.blogger.toc.sorter.AbstractSorter'], []); -goog.addDependency('../../../../src/blogger/toc/sorter/publisheddatesorter.js', ['garafu.blogger.toc.sorter.PublishedDateSorter'], ['garafu.blogger.toc.sorter.AbstractSorter']); -goog.addDependency('../../../../src/blogger/toc/sorter/titlenamesorter.js', ['garafu.blogger.toc.sorter.TitleNameSorter'], ['garafu.blogger.toc.sorter.AbstractSorter']); -goog.addDependency('../../../../src/blogger/toc/sorter/updateddatesorter.js', ['garafu.blogger.toc.sorter.UpdatedDateSorter'], ['garafu.blogger.toc.sorter.AbstractSorter']); -goog.addDependency('../../../../src/date/W3CDTF.js', ['garafu.date.W3CDTF'], []); +goog.addDependency('../../../../src/blogger/toc/printer/AbstractPrinter.js', ['garafu.blogger.toc.printer.AbstractPrinter'], []); +goog.addDependency('../../../../src/blogger/toc/printer/Category.js', ['garafu.blogger.toc.printer.Category'], []); +goog.addDependency('../../../../src/blogger/toc/printer/Entry.js', ['garafu.blogger.toc.printer.Entry'], ['garafu.date.W3CDTF']); +goog.addDependency('../../../../src/blogger/toc/printer/LabelContentsOrderPrinter.js', ['garafu.blogger.toc.printer.LabelContentsOrderPrinter'], ['garafu.blogger.toc.printer.LabelPrinter']); +goog.addDependency('../../../../src/blogger/toc/printer/LabelNameOrderPrinter.js', ['garafu.blogger.toc.printer.LabelNameOrderPrinter'], ['garafu.blogger.toc.printer.LabelPrinter']); +goog.addDependency('../../../../src/blogger/toc/printer/LabelPrinter.js', ['garafu.blogger.toc.printer.LabelPrinter'], ['garafu.blogger.toc.printer.AbstractPrinter', 'garafu.blogger.toc.printer.Category', 'garafu.blogger.toc.printer.Entry']); +goog.addDependency('../../../../src/blogger/toc/printer/TitlePrinter.js', ['garafu.blogger.toc.printer.TitlePrinter'], ['garafu.blogger.toc.printer.AbstractPrinter', 'garafu.blogger.toc.printer.Entry']); +goog.addDependency('../../../../src/blogger/toc/settings.js', ['garafu.blogger.toc.Settings'], ['garafu.i18n.DateTimeFormat']); +goog.addDependency('../../../../src/blogger/toc/sorter/AbstractSorter.js', ['garafu.blogger.toc.sorter.AbstractSorter'], []); +goog.addDependency('../../../../src/blogger/toc/sorter/PublishedDateSorter.js', ['garafu.blogger.toc.sorter.PublishedDateSorter'], ['garafu.blogger.toc.sorter.AbstractSorter']); +goog.addDependency('../../../../src/blogger/toc/sorter/TitleNameSorter.js', ['garafu.blogger.toc.sorter.TitleNameSorter'], ['garafu.blogger.toc.sorter.AbstractSorter']); +goog.addDependency('../../../../src/blogger/toc/sorter/UpdatedDateSorter.js', ['garafu.blogger.toc.sorter.UpdatedDateSorter'], ['garafu.blogger.toc.sorter.AbstractSorter']); +goog.addDependency('../../../../src/date/W3CDTF.js', ['garafu.date.W3CDTF'], ['garafu.string']); goog.addDependency('../../../../src/dom/dom.js', ['garafu.dom'], []); goog.addDependency('../../../../src/events/events.js', ['garafu.events'], []); +goog.addDependency('../../../../src/i18n/DateTimeFormat.js', ['garafu.i18n.DateTimeFormat'], ['garafu.i18n.DateTimeSymbols', 'garafu.string']); +goog.addDependency('../../../../src/i18n/DateTimeSymbols.js', ['garafu.i18n.DateTimeSymbols'], []); +goog.addDependency('../../../../src/string/string.js', ['garafu.string'], []); diff --git a/src/i18n/DateTimeFormat.js b/src/i18n/DateTimeFormat.js new file mode 100644 index 0000000..ac8c314 --- /dev/null +++ b/src/i18n/DateTimeFormat.js @@ -0,0 +1,426 @@ +// ************************************************************************************************* +// +// DateTimeFormat class +// +// summary +// inheritance - +// ************************************************************************************************* + +goog.provide('garafu.i18n.DateTimeFormat'); + +goog.require('garafu.i18n.DateTimeSymbols'); +goog.require('garafu.string'); + + + +// ------------------------------------------------------------------------------------------------- +// constructor +// ------------------------------------------------------------------------------------------------- + + +/** +* Initialize a new instance of the DateFormat class. +* +* @public +* @constructor +* @param {string|garafu.i18n.DateTimeFormat.Format} pattern The format pattern. +* @param {string} locale Locale string. +* +* @class This class provide internationalize the Date format function. +*
+* Symbol  Meaning                                                                                       Example
+* ------  ------                                                                                        ------
+* d       The day of the month. Single-digit days do not have a leading zero.                            3
+* dd      The day of the month. Single-digit days have a leading zero.                                  03
+* E       The abbreviated name of the day of the week, as defined in "DateTimeSymbols.SHORTWEEKDAYS".   Tue  
+* EE      The full name of the day of the week, as defined in "DateTimeSymbols.WEEKDAYS".               Tuesday
+* G       The period or era.                                                                            AD
+* h       The hour in a 12-hour clock. Single-digit hours do not have a leading zero.                    5
+* hh      The hour in a 12-hour clock. Single-digit hours have a leading zero.                          05
+* H       The hour in a 24-hour clock. Single-digit hours do not have a leading zero.                    8
+* HH      The hour in a 24-hour clock. Single-digit hours have a leading zero.                          08
+* m       The minute. Single-digit minuites do not have a leading zero.                                  2
+* mm      The minute. Single-digit minuites have a leading zero.                                        02
+* M       The numeric month.                                                                            6
+* MM      The numeric month. Single-digit months have a leading zero.                                   06
+* MMM     The abbreviated name of the month, as defined in "DateTimeSymbols.SHORTMONTH"                 Jun
+* MMMM    The full name of the month, as defined in "DateTimeSymbols.MONTHS"                            June
+* s       The second. Single-digit months do not have a leading zero.                                   6
+* ss      The second. Single-digit minuites have a leading zero.                                        06
+* t       The first character in the AM/PM designator, as defined in "DateTimeSymbols.AMPMS"            AM
+* yy      The year without the century.                                                                 98
+* yyyy    The year in four digits, including the century.                                               1998
+* z       The time zone offset. Single-digit hours do not have a leading zero.                          -8
+* zz      The time zone offset. Single-digit hours have a leading zero.                                 -08
+* zzz     The full time zone offset. Single-digit hours and minutes have leading zeros.                 -08:00
+* 
+* @property {string} pattern Date format pattern string. +* @property {string[]} patternParts Separated pattern string. +* @property {string} locale Locale string. +*/ +garafu.i18n.DateTimeFormat = function (pattern, locale) { + this.symbols = new garafu.i18n.DateTimeSymbols(locale); + + if (typeof pattern === 'number') { + pattern = this.getStandardPattern(pattern); + } + + this.pattern = pattern; + this.patternParts = []; + this.locale = locale; + + this.initialize(); +}; + + +// ------------------------------------------------------------------------------------------------- +// enum +// ------------------------------------------------------------------------------------------------- + +/** +* Enum to identify predefined Date/Time format pattern. +*
    +*
  • FULL_DATE
  • +*
  • LONG_DATE
  • +*
  • MEDIUM_DATE
  • +*
  • SHORT_DATE
  • +*
  • FULL_TIME
  • +*
  • LONG_TIME
  • +*
  • MEDIUM_TIME
  • +*
  • SHORT_TIME
  • +*
  • FULL_DATETIME
  • +*
  • LONG_DATETIME
  • +*
  • MEDIUM_DATETIME
  • +*
  • SHORT_DATETIME
  • +*
+* +* @public +* @constant +* @type enum +* @see garafu.i18n.DateTimeSymbols +*/ +garafu.i18n.DateTimeFormat.Format = { + FULL_DATE: 0, + LONG_DATE: 1, + MEDIUM_DATE: 2, + SHORT_DATE: 3, + FULL_TIME: 4, + LONG_TIME: 5, + MEDIUM_TIME: 6, + SHORT_TIME: 7, + FULL_DATETIME: 8, + LONG_DATETIME: 9, + MEDIUM_DATETIME: 10, + SHORT_DATETIME: 11 +}; + + + +/** +* Enum of field type. +*
    +*
  • LITERAL
  • +*
  • FIELD
  • +*
+* +* @private +* @constant +* @type enum +*/ +garafu.i18n.DateTimeFormat.PatternType = { + LITERAL: 0, + FIELD: 1 +}; + + +// ------------------------------------------------------------------------------------------------- +// methods +// ------------------------------------------------------------------------------------------------- + +/** +* Format the given date object according to preset pattern and current locale. +* +* @public +* @param {Date} date The Date object that is being formatted. +* @return {string} Formatted string for the given date. +*/ +garafu.i18n.DateTimeFormat.prototype.format = function (date) { + var patternParts = this.patternParts; + var i, max; + var text; + var out = []; + + for (i = 0, max = patternParts.length; i < max; i++) { + text = patternParts[i].text; + if (garafu.i18n.DateTimeFormat.PatternType.FIELD === patternParts[i].type) { + out.push(this.formatField(text, date)); + } else { + out.push(text); + } + } + + return out.join(''); +}; + + +/** +* +* @private +* @param {garafu.i18n.DateTimeFormat.Format} patternType Enum of defined pattern. +* @return {string} +*/ +garafu.i18n.DateTimeFormat.prototype.getStandardPattern = function (formatType) { + var pattern = ''; + + if (formatType < 4) { + pattern += this.symbols.DATEFORMATS[formatType]; + } else if (formatType < 8) { + pattern += this.symbols.TIMEFORMATS[formatType - 4]; + } else { + pattern += this.symbols.DATEFORMATS[formatType - 8]; + pattern += ' '; + pattern += this.symbols.TIMEFORMATS[formatType - 8]; + } + + return pattern; +}; + + +/** +* Initialize this instance. Create and set formatt pattern string array. +* +* @private +*/ +garafu.i18n.DateTimeFormat.prototype.initialize = function () { + var parts = this.breakDownPattern(this.pattern); + + this.patternParts = parts; +}; + + +/** +* Break down formatt pattern string to convertable format. +* +* @private +* @param {string} pattern Format pattern string. +* @return {string[]} String that has been splitted. +*/ +garafu.i18n.DateTimeFormat.prototype.breakDownPattern = function (pattern) { + var tokens = [ + new RegExp('^[^\\\'GyMdHhtmsEz]+'), + new RegExp('^(?:G+|y+|M+|d+|H+|h+|t+|m+|s+|E+|z+)') + ]; + var parts = []; + var part, m, i; + + while (pattern) { + for (i = tokens.length; i--;) { + m = pattern.match(tokens[i]); + if (m) { + part = m[0]; + pattern = pattern.substring(part.length); + parts.push({ text: part, type: i }); + break; + } + } + } + + return parts; +}; + + + + +/** +* Format Era field according to pattern specified. +* +* @private +* @return {string} +*/ +garafu.i18n.DateTimeFormat.prototype.formatEra = function (count, date) { + var value = date.getFullYear() > 0 ? 1 : 0; + return this.symbols.ERAS[value]; +}; + + + + +/** +* Format Year field according to pattern specified. +* +* @private +* @return {string} +*/ +garafu.i18n.DateTimeFormat.prototype.formatYear = function (count, date) { + var value = date.getFullYear(); + if (value < 0) { + value = -value; + } + return count === 2 ? garafu.string.paddingNumber(value % 100, 2) : String(value); +}; + + + + +/** +* Format Month field according to pattern specified. +* +* @private +* @return {string} +*/ +garafu.i18n.DateTimeFormat.prototype.formatMonth = function (count, date) { + var value = date.getMonth(); + switch (count) { + case 3: + return this.symbols.SHORTMONTH[value]; + case 4: + return this.symbols.MONTHS[value]; + default: + return garafu.string.paddingNumber(value + 1, count); + } +}; + + + + +/** +* Format Date field according to pattern specified. +* +* @private +* @return {string} +*/ +garafu.i18n.DateTimeFormat.prototype.formatDate = function (count, date) { + return garafu.string.paddingNumber(date.getDate(), count); +}; + + + + +/** +* Formats (0..23) hours field according pattern specified. +* +* @private +* @return {string} +*/ +garafu.i18n.DateTimeFormat.prototype.format24Hours = function (count, date) { + return garafu.string.paddingNumber(date.getHours(), count); +}; + + + + +/** +* Formats (0..11) hours field according pattern specified. +* +* @private +* @return {string} +*/ +garafu.i18n.DateTimeFormat.prototype.format12Hours = function (count, date) { + return garafu.string.paddingNumber(date.getHours() % 12, count); +}; + + + + +/** +* Formats Am/Pm field according pattern specified. +* +* @private +* @return {string} +*/ +garafu.i18n.DateTimeFormat.prototype.formatAmPm = function (count, date) { + var hours = date.getHours(); + return this.symbols.AMPMS[hours >= 12 && hours < 24 ? 1 : 0]; +}; + + + + +/** +* Formats Minutes field according to pattern specified. +* +* @private +* @return {string} +*/ +garafu.i18n.DateTimeFormat.prototype.formatMinutes = function (count, date) { + return garafu.string.paddingNumber(date.getMinutes(), count); +}; + + + +/** +* Formats Seconds field according to pattern specified. +* +* @private +* @return {string} +*/ +garafu.i18n.DateTimeFormat.prototype.formatSeconds = function (count, date) { + return garafu.string.paddingNumber(date.getSeconds(), count); +}; + + + + +/** +* Formats Day of week field according to pattern specified. +* +* @private +* @return {string} +*/ +garafu.i18n.DateTimeFormat.prototype.formatDayOfWeek = function (count, date) { + var value = date.getDay(); + return count >= 4 ? this.symbols.WEEKDAYS[value] : this.symbols.SHORTWEEKDAYS[value]; +}; + + + + +/** +* Formats Timezone field according to pattern specified. +* +* @private +* @return {string} +*/ +garafu.i18n.DateTimeFormat.prototype.formatTimeZone = function (count, date) { + var value = date.getTimezoneOffset() / 60; + return value < 0 ? value : '+' + value; +}; + + + + +/** +* +* +* @private +* @return {string} +*/ +garafu.i18n.DateTimeFormat.prototype.formatField = function (pattern, date) { + var count = pattern.length; + switch (pattern.charAt(0)) { + case 'G': + return this.formatEra(count, date); + case 'y': + return this.formatYear(count, date); + case 'M': + return this.formatMonth(count, date); + case 'd': + return this.formatDate(count, date); + case 'H': + return this.format24Hours(count, date); + case 'h': + return this.format12Hours(count, date); + case 't': + return this.formatAmPm(count, date); + case 'm': + return this.formatMinutes(count, date); + case 's': + return this.formatSeconds(count, date); + case 'E': + return this.formatDayOfWeek(count, date); + case 'z': + return this.formatTimeZone(count, date); + default: + return ''; + } +}; diff --git a/src/i18n/DateTimeSymbols.js b/src/i18n/DateTimeSymbols.js new file mode 100644 index 0000000..e84d901 --- /dev/null +++ b/src/i18n/DateTimeSymbols.js @@ -0,0 +1,70 @@ +// ************************************************************************************************* +// +// DateTimeSymbols class +// +// summary +// inheritance - +// ************************************************************************************************* + +goog.provide('garafu.i18n.DateTimeSymbols'); + + + + +/** +* Initialize a new instance of the DateTimeSymbols class. +* +* @constructor +* @param {string} locale Locale string. +* +* @class Containes and provide Date symbols. +*/ +garafu.i18n.DateTimeSymbols = function (locale) { + var symbols = null; + + switch (locale) { + case 'en-us': + symbols = garafu.i18n.DateTimeSymbols.en_us; + break; + case 'ja-jp': + symbols = garafu.i18n.DateTimeSymbols.ja_jp; + break; + default: + symbols = garafu.i18n.DateTimeSymbols.en_us; + } + + return symbols; +}; + + +/** +* Date/time formatting symbols for locale "en-us". +*/ +garafu.i18n.DateTimeSymbols.en_us = { + ERAS: ['BC', 'AD'], + SHORTMONTH: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], + MONTHS: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], + SHORTWEEKDAYS: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], + WEEKDAYS: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], + AMPMS: ['AM', 'PM'], + DATEFORMATS: ['EEEE dd MMMM y', 'dd MMMM y', 'dd MMM y', 'yyyy/MM/dd'], + TIMEFORMATS: ['h:mm:ss t zzzz', 'h:mm:ss t z', 'h:mm:ss t', 'h:mm t'] +}; + + + +/** +* Date/time formatting symbols for locale "ja-jp". +*/ +garafu.i18n.DateTimeSymbols.ja_jp = { + ERAS: ['紀元前', '西暦'], + SHORTMONTH: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'], + MONTHS: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'], + SHORTWEEKDAYS: ['日曜日', '月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日'], + WEEKDAYS: ['日', '月', '火', '水', '木', '金', '土'], + AMPMS: ['午前', '午後'], + DATEFORMATS: ['y年M月d日(EEEE)', 'y年M月d日', 'yyyy/MM/dd', 'yy/MM/dd'], + TIMEFORMATS: ['H時mm分ss秒 zzzz', 'H:mm:ss z', 'H:mm:ss', 'H:mm'] +}; + + diff --git a/src/string/string.js b/src/string/string.js new file mode 100644 index 0000000..1925c80 --- /dev/null +++ b/src/string/string.js @@ -0,0 +1,27 @@ +goog.provide('garafu.string'); + + + + +/** +* Pads number to given length. +* +* @public +* @param {number} number The number to pad. +* @param {number} length The desired length. +* @return {string} The number string padded to given length. +*/ +garafu.string.paddingNumber = function (number, length) { + var source = String(number); + var count = length - source.length; + + if (count <= 0) { + return source; + } + + while (count--) { + source = '0' + source; + } + + return source; +}; \ No newline at end of file diff --git a/stylesheets/simple.css b/stylesheets/simple.css index a7280ae..87a2bd6 100644 --- a/stylesheets/simple.css +++ b/stylesheets/simple.css @@ -19,14 +19,18 @@ } #main .poststoc-item { + margin: 2px 0; } #main .poststoc-entry { } +#main .poststoc-entry span +{ + margin: 2px 4px; +} #main .poststoc-thumbnail { display: inline-block; - margin: 2px 4px; } #main .poststoc-thumbnail-image { @@ -43,14 +47,13 @@ } #main .poststoc-published { - display: none; } #main .poststoc-updated { - display: none; } #main .poststoc-title { + margin-left: 4px; text-decoration: none; color: #2288bb; } diff --git a/stylesheets/tile_emerald.css b/stylesheets/tile_emerald.css index 06cd4e0..fdbdeac 100644 --- a/stylesheets/tile_emerald.css +++ b/stylesheets/tile_emerald.css @@ -1,7 +1,7 @@ #main .poststoc { font-size: 12px; - font-family: Trebuchet MS', Trebuchet, Verdana, sans-serif; + font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; } #main .poststoc-category { @@ -41,11 +41,17 @@ #main .poststoc-entry { padding-left: 10px; + vertical-align: top; +} +#main .poststoc-entry span { + vertical-align: top; + margin: 2px 4px; } #main .poststoc-thumbnail { display: inline-block; - margin: 2px 4px; + position: relative; + top: -8px; } #main .poststoc-thumbnail-image { @@ -62,14 +68,13 @@ } #main .poststoc-published { - display: none; } #main .poststoc-updated { - display: none; } #main .poststoc-title { + margin-left: 4px; text-decoration: none; color: #2288bb; } diff --git a/stylesheets/tile_steel.css b/stylesheets/tile_steel.css index 270ff85..33a017d 100644 --- a/stylesheets/tile_steel.css +++ b/stylesheets/tile_steel.css @@ -1,7 +1,7 @@ #main .poststoc { font-size: 12px; - font-family: Trebuchet MS', Trebuchet, Verdana, sans-serif; + font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; } #main .poststoc-category { @@ -41,11 +41,17 @@ #main .poststoc-entry { padding-left: 10px; + vertical-align: top; +} +#main .poststoc-entry span { + vertical-align: top; + margin: 2px 4px; } #main .poststoc-thumbnail { display: inline-block; - margin: 2px 4px; + position: relative; + top: -8px; } #main .poststoc-thumbnail-image { @@ -62,14 +68,13 @@ } #main .poststoc-published { - display: none; } #main .poststoc-updated { - display: none; } #main .poststoc-title { + margin-left: 4px; text-decoration: none; color: #2288bb; }