Skip to content

Commit

Permalink
fix: consider user selected timezone while exporting the reports
Browse files Browse the repository at this point in the history
problem:
Time in CSV exported reports are always in UTC timezone irrespective of user
selected timezone in the UI. There are use case when time in the exported
reports should be other timezone than UTC.

fix:
plywood passes the user selected timezone to format function here
https://github.com/implydata/plywood/blob/master/src/datatypes/dataset.ts#L343
We can use that to get time in the user selected timezone. The time in reports
will also have information about timezone because of ISO format.
  • Loading branch information
metapraveen committed Feb 16, 2021
1 parent 9af37a0 commit 79532d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/client/utils/tabular-options/tabular-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Timezone } from "chronoshift";
import { List } from "immutable";
import { AttributeInfo, TabulatorOptions, TimeRange } from "plywood";
import { Essence } from "../../../common/models/essence/essence";
import { ConcreteSeries, SeriesDerivation } from "../../../common/models/series/concrete-series";
import { formatISODateTime } from "../../../common/utils/time/time";

interface SeriesWithDerivation {
series: ConcreteSeries;
Expand All @@ -37,7 +38,7 @@ function findSeriesAndDerivation(name: string, concreteSeriesList: List<Concrete
export default function tabularOptions(essence: Essence): TabulatorOptions {
return {
formatter: {
TIME_RANGE: (range: TimeRange) => range.start.toISOString()
TIME_RANGE: (range: TimeRange, timezone: Timezone) => formatISODateTime(range.start, timezone)
},
attributeFilter: ({ name }: AttributeInfo) => {
return findSeriesAndDerivation(name, essence.getConcreteSeries()) !== null
Expand Down
5 changes: 5 additions & 0 deletions src/common/utils/time/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Unary } from "../functional/functional";

const ISO_FORMAT_DATE = "YYYY-MM-DD";
const ISO_FORMAT_TIME = "HH:mm";
const ISO_FORMAT = "YYYY-MM-DDTHH:mm:ss.sssZ"
const FORMAT_FULL_MONTH_WITH_YEAR = "MMMM YYYY";

export function getMoment(date: Date, timezone: Timezone): Moment {
Expand Down Expand Up @@ -166,6 +167,10 @@ export function formatDateTime(date: Date, timezone: Timezone): string {
return getMoment(date, timezone).format(FULL_FORMAT);
}

export function formatISODateTime(date: Date, timezone: Timezone): string {
return getMoment(date, timezone).format(ISO_FORMAT);
}

export function formatISODate(date: Date, timezone: Timezone): string {
return getMoment(date, timezone).format(ISO_FORMAT_DATE);
}
Expand Down

0 comments on commit 79532d4

Please sign in to comment.