﻿<?xml version="1.0" encoding="UTF-8"?>


<!--

Copyright 2008,2009 Maxim Sajin <joox@dapmx.org>

This file is part of Dap Starter Kit.

	Dap Starter Kit is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published 
	by the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Dap Starter Kit is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	See the GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with Dap Starter Kit. If not, see <http://www.gnu.org/licenses/>.

	Dap Starter Kit home page: <http://dapmx.org/starter-kit/>.

-->


<fo src="dapmx.org/0.1.5/starter-kit/moreconverts.xml">

	<![CDATA[
	
		dapx.fo={
		
			
		
			convert:{
			
				date	:function(datetime){return datetime?datetime.split("T")[0].split("-").reverse().join("."):""},
				time	:function(datetime){return datetime?datetime.split("T")[1].substr(0,5):"";},
				fulldt	:function(datetime){return dapx.fo.convert.date(datetime)+" "+dapx.fo.convert.time(datetime)},
				qdate	:function(datetime){if(!datetime)return""; var d=datetime.split("T")[0].split("-");return d[2]+" "+dapx.fo.months[parseInt(d[1])]},
				qdt		:function(datetime){return datetime?dapx.fo.convert.qdate(datetime)+" "+dapx.fo.convert.time(datetime):""},
		
				num		:function(n){
							if(!(n=parseInt(n)))return("0");
							var s=n<0?"-":"",k;
							n*=n/Math.abs(n);
							while(n>=1000) s=","+((k=n%1000)+1000)+s, n-=k, n*=0.001;
							return n+s.replace(/,1/g," ");
						},
				"!num"	:function(value){return parseInt(value.replace(/\s/g,""))},

				numspell:function(n){
							var M=Math.floor(n/1e6),k=Math.floor((n-M*1e6)/1e3),spell="";
							n-=(M*1e6+k*1e3);
							if(M)spell+=dapx.fo.mille(M)+" миллионов ";
							if(k)spell+=dapx.fo.mille(k)+" тысяч ";
							if(n)spell+=dapx.fo.mille(n);
							return spell;
						},
				
				ext		:function(fname){if(!fname)return null;var s=fname.split(".");return s.length>1?s[s.length-1]:""}	/// file extension
				
			},

			
			/// private:
			
			months:["","янв","фев","мар","апр","май","июн","июл","авг","сен","окт","ноя","дек"],
			
			numspell:{
				slashblank:new RegExp("/ ","g"),
				hs:["","сто ","двести ","триста ","четыреста ","пятьсот ","шестьсот ","семьсот ","восемьсот ","девятьсот "],
				ds:["","","двадцать ","тридцать ","сорок ","пятьдесят ","шестьдесят ","семьдесят ","восемьдесят ","девяноста "],
				es:["","один ","два ","три ","четыре ","пять ","шесть ","семь ","восемь ","девять "],
				ts:["десять ","одинадцать ","двенадцать ","тринадцать ","четырнадцать ","пятнадцать ","шестнадцать ","семнадцать ","восемнадцать ","девятнадцать "]
			},
			
			mille:function(n){
				var h=Math.floor(n/100),d=Math.floor((n-h*100)/10),spell="";
				n-=(h*100+d*10);
				if(h)spell+=dapx.fo.convert.numspell.hs[h];
				if(d!=1)spell+=(dapx.fo.convert.numspell.ds[d]+dapx.fo.convert.numspell.es[n]);
				else spell+=dapx.fo.convert.numspell.ts[n];
				return spell;
			}
					
		}
		
	]]>
	
	<about>Some formats</about>

</fo>
