Skip to content

Commit

Permalink
[changed] globalize localizer now a function that takes a globalize i…
Browse files Browse the repository at this point in the history
…nstance
  • Loading branch information
jquense committed Oct 3, 2015
1 parent 03e41be commit 31c5479
Showing 1 changed file with 12 additions and 33 deletions.
45 changes: 12 additions & 33 deletions src/globalize-localizers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
var { NumberLocalizer, DateLocalizer } = require('./util/localizers')
var dates = require('date-arithmetic')
import dates from './util/dates';

function globalizeDateLocalizer(globalize){
export default function globalizeLocalizers(globalize) {
const shortNames = Object.create(null);

function getCulture(culture){
return culture
? (localizer.globalize || globalize).findClosestCulture(culture)
: (localizer.globalize || globalize).culture()
? globalize.findClosestCulture(culture)
: globalize.culture()
}

function firstOfWeek(culture) {
Expand All @@ -29,7 +28,7 @@ function globalizeDateLocalizer(globalize){
return names[dayOfTheWeek];
}

var localizer = new DateLocalizer({
var date = {

formats: {
date: 'd',
Expand All @@ -52,40 +51,26 @@ function globalizeDateLocalizer(globalize){
firstOfWeek,

parse(value, format, culture){
return (this.globalize || globalize).parseDate(value, format, culture)
return globalize.parseDate(value, format, culture)
},

format(value, format, culture){
return (this.globalize || globalize).format(value, format, culture)
return globalize.format(value, format, culture)
}
})

// Back-compat cruft, expose the globalize instance so setGlobalizeInstance can mutate it after initialization
// this works b/c there is no need to change the default prop values
localizer.globalize = globalize
return localizer
}

function globalizeNumberLocalizer(globalize) {

function getCulture(culture){
return culture
? (localizer.globalize || globalize).findClosestCulture(culture)
: (localizer.globalize || globalize).culture()
}

var localizer = new NumberLocalizer({
var number = {

formats: {
default: 'D'
},

parse(value, culture){
return (this.globalize || globalize).parseFloat(value, 10, culture)
return globalize.parseFloat(value, 10, culture)
},

format(value, format, culture){
return (this.globalize || globalize).format(value, format, culture)
return globalize.format(value, format, culture)
},

precision(format, _culture){
Expand All @@ -104,13 +89,7 @@ function globalizeNumberLocalizer(globalize) {

return null
}
})

// see point above
localizer.globalize = globalize
return localizer
}
}

module.exports = {
globalizeNumberLocalizer, globalizeDateLocalizer
return { date, number}
}

0 comments on commit 31c5479

Please sign in to comment.