-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add format.timeFormatter
to get raw access to the formatter
#31
Add format.timeFormatter
to get raw access to the formatter
#31
Conversation
Hey! Thanks for the PR. What do you think about exporting the // index.ts
export {
getDateFormatter,
getNumberFormatter,
getTimeFormatter,
getMessageFormatter,
} from './includes/formatters' Then you would be able to pass a locale and all the other parameters you want. |
@kaisermann I'm ok with that, but unless I'm mistaken if the user changes the selected locale, the app wouldn't be notified the same way they are when using store, right? For completenes, this is a store I've created that returns a function that knows how to format the time of the next high/low tide import { t } from "svelte-i18n";
export const formatNextTideDate = derived([t], ([format]) => {
return (nextTideDate, centerDate) => {
let centerDateInSeconds = centerDate.getTime() / 1000;
let nextTideDateInSeconds = nextTideDate.getTime() / 1000;
if (
centerDateInSeconds >= nextTideDateInSeconds - FIFTEEN_MINUTES_IN_SECONDS &&
centerDateInSeconds <= nextTideDateInSeconds + FIFTEEN_MINUTES_IN_SECONDS
) {
return format("tide.now");
} else {
return format.time(nextTideDate, { format: 'short' });
}
}
}); |
Yeah, being a low-level API, you would need to keep the import { t, locale } from '...'
export const customFormatThingie = derived([t, locale], (format, currentLocale) => ....); Would that help you? |
@kaisermann yeah, that makes sense. I've updated the PR to export the |
be6e92e
to
4bd82fe
Compare
Any feedback on this one that I should address? |
ping |
Hey, @cibernox, I'm going to take a look at this PR's code soon. Been busy with the beginning of the year 😁 |
* Add test * Change approach, export functions to access the formatters instead
Released on |
Great, thanks! |
The reason behind this PR is that I need to call
formatter.formatToParts
instead of simplyformatter.format
.I'm happy to change the approach if you think some other approach is more flexible while allowing to call
formatToParts
.If this approach seems ok I can add the same method for the dateFormatter too.
Fixes #30