## Properties
-| Name | Attribute | Privacy | Type | Default | Description |
-| ------------ | ------------- | ------- | --------------------------------------------------- | ------- | ----------------------------------------------------------------- |
-| `dateFilter` | `date-filter` | public | `(date: Date \| null) => boolean` | | A function used to filter out dates. |
-| `dateParser` | `date-parser` | public | `(value: string) => Date \| undefined \| undefined` | | A function used to parse string value into dates. |
-| `format` | `format` | public | `(date: Date) => string \| undefined` | | A function used to format dates into the preferred string format. |
-| `input` | `input` | public | `string \| HTMLElement \| undefined` | | Reference of the native input connected to the datepicker. |
-| `wide` | `wide` | public | `boolean` | `false` | If set to true, two months are displayed. |
+| Name | Attribute | Privacy | Type | Default | Description |
+| ------------ | ------------- | ------- | --------------------------------------------------- | ------- | --------------------------------------------------------------------- |
+| `dataNow` | `now` | public | `number \| undefined` | | A specific date for the current datetime (timestamp in milliseconds). |
+| `dateFilter` | `date-filter` | public | `(date: Date \| null) => boolean` | | A function used to filter out dates. |
+| `dateParser` | `date-parser` | public | `(value: string) => Date \| undefined \| undefined` | | A function used to parse string value into dates. |
+| `format` | `format` | public | `(date: Date) => string \| undefined` | | A function used to format dates into the preferred string format. |
+| `input` | `input` | public | `string \| HTMLElement \| undefined` | | Reference of the native input connected to the datepicker. |
+| `wide` | `wide` | public | `boolean` | `false` | If set to true, two months are displayed. |
## Methods
diff --git a/src/components/footer/footer.stories.ts b/src/components/footer/footer.stories.ts
index 3c3d391a30..0e230c4767 100644
--- a/src/components/footer/footer.stories.ts
+++ b/src/components/footer/footer.stories.ts
@@ -190,7 +190,7 @@ const TemplateClockColumns = ({ ...args }): TemplateResult => html`
@@ -118,7 +118,7 @@ snapshots["sbb-journey-summary renders with second journey"] =
-
+
diff --git a/src/components/journey-summary/journey-summary.spec.ts b/src/components/journey-summary/journey-summary.spec.ts
index 93162f8863..d4f9c88c32 100644
--- a/src/components/journey-summary/journey-summary.spec.ts
+++ b/src/components/journey-summary/journey-summary.spec.ts
@@ -40,35 +40,35 @@ const dataWithoutVia: InterfaceSbbJourneySummaryAttributes = {
describe(`sbb-journey-summary`, () => {
it('renders', async () => {
const root = (await fixture(
- html` `,
+ html` `,
)) as SbbJourneySummaryElement;
root.trip = data;
await waitForLitRender(root);
expect(root).dom.to.be.equal(`
-
+ `);
await expect(root).shadowDom.to.be.equalSnapshot();
});
it('renders without vias', async () => {
const root = (await fixture(
- html` `,
+ html` `,
)) as SbbJourneySummaryElement;
root.trip = dataWithoutVia;
await waitForLitRender(root);
expect(root).dom.to.be.equal(`
-
+ `);
await expect(root).shadowDom.to.be.equalSnapshot();
});
it('renders with second journey', async () => {
const root = (await fixture(
- html` `,
+ html` `,
)) as SbbJourneySummaryElement;
root.trip = dataWithoutVia;
root.tripBack = data;
@@ -77,7 +77,7 @@ describe(`sbb-journey-summary`, () => {
await waitForLitRender(root);
expect(root).dom.to.be.equal(`
-
+ `);
await expect(root).shadowDom.to.be.equalSnapshot();
});
diff --git a/src/components/journey-summary/journey-summary.stories.ts b/src/components/journey-summary/journey-summary.stories.ts
index 46087dd575..f0951cc987 100644
--- a/src/components/journey-summary/journey-summary.stories.ts
+++ b/src/components/journey-summary/journey-summary.stories.ts
@@ -67,18 +67,18 @@ const tripBack: InputType = {
const defaultArgTypes: ArgTypes = {
'disable-animation': disableAnimation,
- 'data-now': now,
'round-trip': roundTrip,
'header-level': headerLevel,
+ now,
trip,
tripBack,
};
const defaultArgs: Args = {
'disable-animation': isChromatic(),
- 'data-now': new Date('2022-12-05T12:11:00').valueOf(),
'round-trip': false,
'header-level': headerLevel.options![2],
+ now: new Date('2022-12-05T12:11:00').valueOf(),
trip: undefined,
tripBack: undefined,
};
diff --git a/src/components/journey-summary/journey-summary.ts b/src/components/journey-summary/journey-summary.ts
index 643f648592..883096acd3 100644
--- a/src/components/journey-summary/journey-summary.ts
+++ b/src/components/journey-summary/journey-summary.ts
@@ -8,7 +8,6 @@ import {
defaultDateAdapter,
durationToTime,
removeTimezoneFromISOTimeString,
- readDataNow,
} from '../core/datetime.js';
import { i18nTripDuration } from '../core/i18n.js';
import type { Leg } from '../core/timetable.js';
@@ -63,6 +62,9 @@ export class SbbJourneySummaryElement extends LitElement {
*/
@property({ attribute: 'disable-animation', type: Boolean }) public disableAnimation?: boolean;
+ /** A specific date for the current datetime (timestamp in milliseconds). */
+ @property({ attribute: 'now' }) public dataNow?: number;
+
private _hasContentSlot: boolean = false;
private _language = new SbbLanguageController(this);
@@ -72,8 +74,7 @@ export class SbbJourneySummaryElement extends LitElement {
}
private _now(): number {
- const dataNow = readDataNow(this);
- return isNaN(dataNow) ? Date.now() : dataNow;
+ return this.dataNow ?? Date.now();
}
/** renders the date of the journey or if it is the current or next day */
@@ -136,7 +137,7 @@ export class SbbJourneySummaryElement extends LitElement {
.arrivalWalk=${arrivalWalk}
.legs=${legs}
.disableAnimation=${this.disableAnimation}
- data-now=${this._now()}
+ now=${this._now()}
>
`;
diff --git a/src/components/journey-summary/readme.md b/src/components/journey-summary/readme.md
index 471cf86d84..81e88f4bd4 100644
--- a/src/components/journey-summary/readme.md
+++ b/src/components/journey-summary/readme.md
@@ -16,12 +16,16 @@ If the tripBack prop is passed to the component a second journey-summary, withou
```
+To specify a specific date for the current datetime, you can use the `now` property (timestamp in milliseconds).
+This is helpful if you need a specific state of the component.
+
## Properties
| Name | Attribute | Privacy | Type | Default | Description |
| ------------------ | ------------------- | ------- | --------------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------- |
+| `dataNow` | `now` | public | `number \| undefined` | | A specific date for the current datetime (timestamp in milliseconds). |
| `disableAnimation` | `disable-animation` | public | `boolean \| undefined` | | Per default, the current location has a pulsating animation. You can disable the animation with this property. |
| `headerLevel` | `header-level` | public | `SbbTitleLevel` | `'3'` | Heading level of the journey header element (e.g. h1-h6). |
| `roundTrip` | `round-trip` | public | `boolean \| undefined` | | The RoundTrip prop. This prop controls if one or two arrows are displayed in the header. |
diff --git a/src/components/pearl-chain-time/pearl-chain-time.spec.ts b/src/components/pearl-chain-time/pearl-chain-time.spec.ts
index 55c8e19f52..41762f2838 100644
--- a/src/components/pearl-chain-time/pearl-chain-time.spec.ts
+++ b/src/components/pearl-chain-time/pearl-chain-time.spec.ts
@@ -17,7 +17,7 @@ describe(`sbb-pearl-chain-time`, () => {
`);
@@ -28,7 +28,7 @@ describe(`sbb-pearl-chain-time`, () => {
];
await waitForLitRender(element);
expect(element).dom.to.be.equal(`
-
+
`);
expect(element).shadowDom.to.be.equal(`
@@ -39,7 +39,7 @@ describe(`sbb-pearl-chain-time`, () => {
12:00
-
+
`);
@@ -67,7 +67,7 @@ describe(`sbb-pearl-chain-time`, () => {
];
await waitForLitRender(element);
expect(element).dom.to.be.equal(`
-
+
`);
expect(element).shadowDom.to.be.equal(`
@@ -95,7 +95,7 @@ describe(`sbb-pearl-chain-time`, () => {
12:00
-
+
`);
@@ -123,7 +123,7 @@ describe(`sbb-pearl-chain-time`, () => {
];
await waitForLitRender(element);
expect(element).dom.to.be.equal(`
-
+
`);
expect(element).shadowDom.to.be.equal(`
@@ -134,7 +134,7 @@ describe(`sbb-pearl-chain-time`, () => {
12:00
-
+
`);
@@ -180,7 +180,7 @@ describe(`sbb-pearl-chain-time`, () => {
];
await waitForLitRender(element);
expect(element).dom.to.be.equal(`
-
+
`);
expect(element).shadowDom.to.be.equal(`
@@ -208,7 +208,7 @@ describe(`sbb-pearl-chain-time`, () => {
12:00
-
+
```
-## Testing
-
-To specify a specific date for the current datetime, you can use the `data-now` attribute (timestamp in milliseconds).
+To specify a specific date for the current datetime, you can use the `now` property (timestamp in milliseconds).
This is helpful if you need a specific state of the component.
@@ -58,6 +56,7 @@ This is helpful if you need a specific state of the component.
| ------------------ | ------------------- | ------- | ---------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `arrivalTime` | `arrival-time` | public | `string \| undefined` | | Prop to render the arrival time - will be formatted as "H:mm" |
| `arrivalWalk` | `arrival-walk` | public | `number \| undefined` | | Optional prop to render the walk time (in minutes) after arrival |
+| `dataNow` | `now` | public | `number \| undefined` | | A specific date for the current datetime (timestamp in milliseconds). |
| `departureTime` | `departure-time` | public | `string \| undefined` | | Prop to render the departure time - will be formatted as "H:mm" |
| `departureWalk` | `departure-walk` | public | `number \| undefined` | | Optional prop to render the walk time (in minutes) before departure |
| `disableAnimation` | `disable-animation` | public | `boolean \| undefined` | | Per default, the current location has a pulsating animation. You can disable the animation with this property. |
diff --git a/src/components/pearl-chain/pearl-chain.stories.ts b/src/components/pearl-chain/pearl-chain.stories.ts
index 8e41921982..ab3bceef95 100644
--- a/src/components/pearl-chain/pearl-chain.stories.ts
+++ b/src/components/pearl-chain/pearl-chain.stories.ts
@@ -32,12 +32,12 @@ const now: InputType = {
const defaultArgTypes: ArgTypes = {
'disable-animation': disableAnimation,
- 'data-now': now,
+ now,
};
const defaultArgs: Args = {
'disable-animation': isChromatic(),
- 'data-now': new Date('2022-12-01T12:11:00').valueOf(),
+ now: new Date('2022-12-01T12:11:00').valueOf(),
};
const Template = ({ legs, ...args }: Args): TemplateResult => {
@@ -86,7 +86,7 @@ export const withPosition: StoryObj = {
args: {
...defaultArgs,
legs: [progressLeg],
- 'data-now': new Date('2022-12-05T12:11:00').valueOf(),
+ now: new Date('2022-12-05T12:11:00').valueOf(),
},
};
@@ -96,7 +96,7 @@ export const Past: StoryObj = {
args: {
...defaultArgs,
legs: [pastLeg, pastLeg],
- 'data-now': new Date('2023-11-01T12:11:00').valueOf(),
+ now: new Date('2023-11-01T12:11:00').valueOf(),
},
};
@@ -106,7 +106,7 @@ export const DepartureStopSkipped: StoryObj = {
args: {
...defaultArgs,
legs: [pastLeg, progressLeg, longFutureLeg, redirectedOnDepartureLeg, futureLeg],
- 'data-now': new Date('2022-12-05T12:11:00').valueOf(),
+ now: new Date('2022-12-05T12:11:00').valueOf(),
},
};
@@ -116,7 +116,7 @@ export const ArrivalStopSkipped: StoryObj = {
args: {
...defaultArgs,
legs: [pastLeg, progressLeg, longFutureLeg, redirectedOnArrivalLeg, futureLeg],
- 'data-now': new Date('2022-12-05T12:11:00').valueOf(),
+ now: new Date('2022-12-05T12:11:00').valueOf(),
},
};
@@ -126,7 +126,7 @@ export const FirstStopSkipped: StoryObj = {
args: {
...defaultArgs,
legs: [redirectedOnDepartureLeg, futureLeg, longFutureLeg],
- 'data-now': new Date('2022-12-05T12:11:00').valueOf(),
+ now: new Date('2022-12-05T12:11:00').valueOf(),
},
};
@@ -136,7 +136,7 @@ export const LastStopSkipped: StoryObj = {
args: {
...defaultArgs,
legs: [futureLeg, longFutureLeg, redirectedOnArrivalLeg],
- 'data-now': new Date('2022-12-05T12:11:00').valueOf(),
+ now: new Date('2022-12-05T12:11:00').valueOf(),
},
};
@@ -146,7 +146,7 @@ export const Mixed: StoryObj = {
args: {
...defaultArgs,
legs: [pastLeg, progressLeg, longFutureLeg, cancelledLeg, futureLeg],
- 'data-now': new Date('2022-12-05T12:11:00').valueOf(),
+ now: new Date('2022-12-05T12:11:00').valueOf(),
},
};
diff --git a/src/components/pearl-chain/pearl-chain.ts b/src/components/pearl-chain/pearl-chain.ts
index 46c5a00606..d8168103bb 100644
--- a/src/components/pearl-chain/pearl-chain.ts
+++ b/src/components/pearl-chain/pearl-chain.ts
@@ -4,7 +4,7 @@ import { html, LitElement, nothing } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
-import { readDataNow, removeTimezoneFromISOTimeString } from '../core/datetime.js';
+import { removeTimezoneFromISOTimeString } from '../core/datetime.js';
import type { Leg, PtRideLeg } from '../core/timetable.js';
import { isRideLeg } from '../core/timetable.js';
@@ -35,9 +35,11 @@ export class SbbPearlChainElement extends LitElement {
*/
@property({ attribute: 'disable-animation', type: Boolean }) public disableAnimation?: boolean;
+ /** A specific date for the current datetime (timestamp in milliseconds). */
+ @property({ attribute: 'now' }) public dataNow?: number;
+
private _now(): number {
- const dataNow = readDataNow(this);
- return isNaN(dataNow) ? Date.now() : dataNow;
+ return this.dataNow ?? Date.now();
}
private _getAllDuration(legs: PtRideLeg[]): number {
diff --git a/src/components/pearl-chain/readme.md b/src/components/pearl-chain/readme.md
index 4b9532c8ae..26ace5f998 100644
--- a/src/components/pearl-chain/readme.md
+++ b/src/components/pearl-chain/readme.md
@@ -46,9 +46,7 @@ The `legs` property is mandatory.
```
-## Testing
-
-To specify a specific date for the current datetime, you can use the `data-now` attribute (timestamp in milliseconds).
+To specify a specific date for the current datetime, you can use the `now` property (timestamp in milliseconds).
This is helpful if you need a specific state of the component.
@@ -57,5 +55,6 @@ This is helpful if you need a specific state of the component.
| Name | Attribute | Privacy | Type | Default | Description |
| ------------------ | ------------------- | ------- | ----------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
+| `dataNow` | `now` | public | `number \| undefined` | | A specific date for the current datetime (timestamp in milliseconds). |
| `disableAnimation` | `disable-animation` | public | `boolean \| undefined` | | Per default, the current location has a pulsating animation. You can disable the animation with this property. |
| `legs` | `legs` | public | `(Leg \| PtRideLeg)[] \| undefined` | | Define the legs of the pearl-chain. Format: `{"legs": \[{"duration": 25}, ...]}` `duration` in minutes. Duration of the leg is relative to the total travel time. Example: departure 16:30, change at 16:40, arrival at 17:00. So the change should have a duration of 33.33%. |
diff --git a/src/components/timetable-row/readme.md b/src/components/timetable-row/readme.md
index dc8c2d4404..4e5f98f84d 100644
--- a/src/components/timetable-row/readme.md
+++ b/src/components/timetable-row/readme.md
@@ -39,9 +39,7 @@ _`tripProp` property_
```
-## Testing
-
-To specify a specific date for the current datetime, you can use the `data-now` attribute (timestamp in milliseconds).
+To specify a specific date for the current datetime, you can use the `now` property (timestamp in milliseconds).
This is helpful if you need a specific state of the component.
@@ -54,6 +52,7 @@ This is helpful if you need a specific state of the component.
| `active` | `active` | public | `boolean \| undefined` | | When this prop is true the sbb-card will be in the active state. |
| `boarding` | `boarding` | public | `Boarding \| undefined` | | This will be forwarded to the notices section |
| `cardActionLabel` | `card-action-label` | public | `string \| undefined` | | Hidden label for the card action. It overrides the automatically generated accessibility text for the component. Use this prop to provide custom accessibility information for the component. |
+| `dataNow` | `now` | public | `number \| undefined` | | A specific date for the current datetime (timestamp in milliseconds). |
| `disableAnimation` | `disable-animation` | public | `boolean \| undefined` | | This will be forwarded to the sbb-pearl-chain component - if true the position won't be animated. |
| `loadingPrice` | `loading-price` | public | `boolean` | `false` | The loading state - when this is true it will be render skeleton with an idling animation |
| `loadingTrip` | `loading-trip` | public | `boolean` | `false` | The loading state - when this is true it will be render skeleton with an idling animation |
diff --git a/src/components/timetable-row/timetable-row.spec.ts b/src/components/timetable-row/timetable-row.spec.ts
index 8fff9830e8..5b176c559b 100644
--- a/src/components/timetable-row/timetable-row.spec.ts
+++ b/src/components/timetable-row/timetable-row.spec.ts
@@ -21,13 +21,13 @@ describe(`sbb-timetable-row`, () => {
describe('sbb-timetable-row with defaultTrip', () => {
it('renders component with config', async () => {
- element = await fixture(html``);
+ element = await fixture(html``);
element.trip = defaultTrip as ITripItem;
await waitForLitRender(element);
expect(element).dom.to.be.equal(`
-
+
`);
@@ -87,7 +87,7 @@ describe(`sbb-timetable-row`, () => {
@@ -112,13 +112,13 @@ describe(`sbb-timetable-row`, () => {
describe('sbb-timetable-row with BusTrip', () => {
it('renders component with config', async () => {
- element = await fixture(html``);
+ element = await fixture(html``);
element.trip = busTrip as ITripItem;
await waitForLitRender(element);
expect(element).dom.to.be.equal(`
-
+
`);
@@ -144,7 +144,7 @@ describe(`sbb-timetable-row`, () => {
Direction Spiegel, Blinzern
-
+