-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from ya-erm/dev
Time zone for each operation (Version 2.7.0)
- Loading branch information
Showing
22 changed files
with
335 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
|
||
<style> | ||
button { | ||
min-width: 0; | ||
font-size: 1rem; | ||
font-weight: normal; | ||
padding: 0.75rem; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Gets the time zone offset for a given time zone name. | ||
* @param timeZone The time zone to get the offset for, e.g. 'Europe/London'. | ||
* @param format The format of the offset. Defaults to 'shortOffset'. | ||
* @returns The time zone offset in the specified format: '+HH:mm' or '+h'. | ||
*/ | ||
export function getTimeZoneOffset(timeZone: string, format: 'shortOffset' | 'longOffset' = 'shortOffset') { | ||
try { | ||
const date = Intl.DateTimeFormat([], { timeZone, timeZoneName: format }); | ||
return date.format(new Date()).split(' ')[1].slice(3) || '+00:00'; | ||
} catch (e) { | ||
console.warn(`Failed to get time zone offset for '${timeZone}'`, e); | ||
return undefined; | ||
} | ||
} | ||
|
||
/** | ||
* Converts a long time zone offset to a short time zone offset. | ||
* @param longTimezoneOffset The long time zone offset to convert, e.g. '+02:00' or '-05:00'. | ||
* @returns The short time zone offset, e.g. '+2' or '-5'. | ||
*/ | ||
export function toShortTimezoneOffset(longTimezoneOffset: string) { | ||
return longTimezoneOffset.replace(/([+-])0?(\d+):00/, '$1$2'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<script lang="ts"> | ||
import dayjs from 'dayjs'; | ||
import timezones from 'timezones-list'; | ||
import { memberSettingsStore, membersService } from '$lib/data'; | ||
import { translate } from '$lib/translate'; | ||
import Input from '$lib/ui/Input.svelte'; | ||
import ListGroup from '$lib/ui/list/ListGroup.svelte'; | ||
import { showSuccessToast } from '$lib/ui/toasts'; | ||
import TimeZoneListItem from './TimeZoneListItem.svelte'; | ||
export let onClick: (timezone: string, shift: string) => void; | ||
export let showCurrentTimeZone = true; | ||
$: settings = $memberSettingsStore; | ||
let search: string = ''; | ||
$: filteredTimeZones = timezones.filter( | ||
(tz) => | ||
!search || | ||
tz.label.toLowerCase().includes(search.toLowerCase()) || | ||
tz.label.includes(search.replace(/([+-])(\d){1}/, '$10$2')), | ||
); | ||
const currentTimeZoneCode = dayjs.tz.guess(); | ||
const currentTimeZone = timezones.find((timezone) => timezone.tzCode == currentTimeZoneCode); | ||
$: favoriteTimeZones = timezones.filter((timezone) => settings?.favoriteTimeZones?.includes(timezone.tzCode)); | ||
const addToFavorite = (timezone: string) => { | ||
membersService.updateSettings({ | ||
favoriteTimeZones: [...(settings?.favoriteTimeZones ?? []), timezone], | ||
}); | ||
showSuccessToast($translate('timezones.timezone_added_to_favorites')); | ||
}; | ||
const removeFromFavorite = (timezone: string) => { | ||
membersService.updateSettings({ | ||
favoriteTimeZones: settings?.favoriteTimeZones?.filter((x) => x !== timezone) ?? [], | ||
}); | ||
showSuccessToast($translate('timezones.timezone_removed_from_favorites')); | ||
}; | ||
</script> | ||
|
||
<div class="flex-grow pt-1 px-1 pb-0"> | ||
<Input bind:value={search} placeholder={$translate('common.search')} clearable /> | ||
</div> | ||
|
||
{#if showCurrentTimeZone && currentTimeZone} | ||
<ListGroup title={$translate('timezones.current_time_zone')}> | ||
<TimeZoneListItem timezone={currentTimeZone} {onClick} /> | ||
</ListGroup> | ||
{/if} | ||
|
||
{#if favoriteTimeZones.length > 0} | ||
<ListGroup title={$translate('timezones.favorite_time_zones')}> | ||
{#each favoriteTimeZones as timezone (timezone.tzCode)} | ||
<TimeZoneListItem {timezone} {onClick} onLongClick={removeFromFavorite} /> | ||
{/each} | ||
</ListGroup> | ||
{/if} | ||
|
||
<ListGroup title={$translate('timezones.all_time_zones')}> | ||
{#each filteredTimeZones as timezone (timezone.tzCode)} | ||
<TimeZoneListItem {timezone} {onClick} onLongClick={addToFavorite} /> | ||
{/each} | ||
</ListGroup> | ||
|
||
<div class="pb-1" /> |
Oops, something went wrong.
f3d5211
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
money-keeper – ./
money-keeper-ya-erm.vercel.app
mk-2.vercel.app
my-money-keeper.vercel.app
money-keeper-git-master-ya-erm.vercel.app
money.ya-erm.ru