#64 Show locale-aware date strings
Merged 10 months ago by a2batic. Opened 11 months ago by amitosh.
amitosh/Fedora-app locale-aware-date  into  master

file modified
+4 -20

@@ -3733,13 +3733,11 @@ 

          },

          "balanced-match": {

            "version": "1.0.0",

-           "bundled": true,

-           "optional": true

+           "bundled": true

          },

          "brace-expansion": {

            "version": "1.1.11",

            "bundled": true,

-           "optional": true,

            "requires": {

              "balanced-match": "^1.0.0",

              "concat-map": "0.0.1"

@@ -3756,8 +3754,7 @@ 

          },

          "concat-map": {

            "version": "0.0.1",

-           "bundled": true,

-           "optional": true

+           "bundled": true

          },

          "console-control-strings": {

            "version": "1.1.0",

@@ -3886,7 +3883,6 @@ 

          "minimatch": {

            "version": "3.0.4",

            "bundled": true,

-           "optional": true,

            "requires": {

              "brace-expansion": "^1.1.7"

            }

@@ -5724,7 +5720,8 @@ 

      "lodash": {

        "version": "4.17.5",

        "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz",

-       "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw=="

+       "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==",

+       "dev": true

      },

      "lodash-es": {

        "version": "4.17.10",

@@ -6310,19 +6307,6 @@ 

          }

        }

      },

-     "moment": {

-       "version": "2.20.1",

-       "resolved": "https://registry.npmjs.org/moment/-/moment-2.20.1.tgz",

-       "integrity": "sha512-Yh9y73JRljxW5QxN08Fner68eFLxM5ynNOAw2LbIB1YAGeQzZT8QFSUvkAz609Zf+IHhhaUxqZK8dG3W/+HEvg=="

-     },

-     "moment-timezone": {

-       "version": "0.5.14",

-       "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.14.tgz",

-       "integrity": "sha1-TrOP+VOLgBCLpGekWPPtQmjM/LE=",

-       "requires": {

-         "moment": ">= 2.9.0"

-       }

-     },

      "ms": {

        "version": "2.0.0",

        "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",

file modified
-3

@@ -61,10 +61,7 @@ 

      "ionic-angular": "3.9.2",

      "ionic-plugin-keyboard": "^2.2.1",

      "ionicons": "^3.0.0",

-     "lodash": "^4.14.0",

      "lodash-es": "^4.17.10",

-     "moment": "^2.14.1",

-     "moment-timezone": "^0.5.5",

      "query-string": "^4.2.2",

      "reflect-metadata": "^0.1.3",

      "rxjs": "5.5.2",

@@ -31,8 +31,8 @@ 

          </ion-card-content>

          <ion-row center>

            <ion-col width-67 padding>

-             <p>{{ meeting.displayTime.dateString }}</p>

-             <p>{{ meeting.displayTime.timeString }}</p>

+             <p><ion-icon name="calendar"></ion-icon> {{ meeting.time.toLocaleDateString() }}</p>

+             <p><ion-icon name="time"></ion-icon> {{ meeting.time.toLocaleTimeString() }}</p>

            </ion-col>

            <ion-col width-33 padding>

              <button ion-button id="add_button" small tappable (click)="addToCalendar(meeting)">

@@ -1,8 +1,4 @@ 

  import { Injectable } from '@angular/core';

- 

- import * as _ from 'lodash';

- import * as moment from 'moment-timezone';

- 

  import { HttpClient } from '@angular/common/http';

  import { Storage } from '@ionic/storage';

  import { Observable } from 'rxjs/Observable';

@@ -10,6 +6,7 @@ 

  import { merge } from 'rxjs/observable/merge';

  import { tap, map } from 'rxjs/operators';

  import { chooseEndpoint, defaultValue } from '../../utils';

+ import { startCase } from 'lodash-es';

  

  /**

   * FedoCal API endpoint

@@ -23,15 +20,6 @@ 

   */

  const CALENDAR_STORAGE_KEY = 'fedocal__calendars';

  

- /**

-  * Date format for display

-  */

- const DATE_FORMAT = 'dddd, MMMM Do YYYY';

- 

- /**

-  * Time format for display

-  */

- const TIME_FORMAT = 'h:mm A z';

  

  /**

   * Convert calendar name from API to a value suitable for display

@@ -48,7 +36,7 @@ 

      case 'fesco':

        return 'FESCo';

      default:

-       return /^[A-Z][^\d-]*.*$/.test(name) ? name : _.startCase(name);

+       return /^[A-Z][^\d-]*.*$/.test(name) ? name : startCase(name);

    }

  }

  

@@ -63,19 +51,6 @@ 

  }

  

  /**

-  * Convert a date consisting of date, time and timezone as different strings to

-  * a single momentjs date

-  *

-  * @param date     Date string

-  * @param time     Time string

-  * @param timezone Timezone identifier

-  */

- function dateToMoment(date: string, time: string, timezone: string) {

-   const m = moment.tz(`${date} ${time}`, timezone).tz('UTC');

-   return m;

- }

- 

- /**

   * A calendar on FedoCal

   *

   * Calendars are assoicated with a group / SIG / or event. They contain a number

@@ -152,22 +127,6 @@ 

     * Meeting end time

     */

    timeEnd: Date,

- 

-   /**

-    * Start time formatted for display

-    */

-   displayTime: {

-     dateString: string,

-     timeString: string,

-   },

- 

-   /**

-    * End time formatted for display

-    */

-   displayTimeEnd: {

-     dateString: string,

-     timeString: string,

-   }

  }

  

  /**

@@ -245,23 +204,16 @@ 

      return this.http.get(`${ENDPOINT}/meetings/`, { params: { calendar: calendar.realName } })

        .pipe(

          map((data: any) => data.meetings.map(m => {

-           const mTime = dateToMoment(m.meeting_date, m.meeting_time_start, m.meeting_timezone);

-           const mTimeEnd = dateToMoment(m.meeting_date_end, m.meeting_time_stop, m.meeting_timezone);

+           // FedoCal splits an ISO8601 string and sends us the date and time,

+           // combine them together

+           const mTime = new Date(`${m.meeting_date}T${m.meeting_time_start}Z`);

+           const mTimeEnd = new Date(`${m.meeting_date_end}T${m.meeting_time_end}Z`);

  

            return {

              name: m.meeting_name,

              description: m.meeting_information,

-             time: mTime.toDate(),

-             timeEnd: mTimeEnd.toDate(),

-             displayTime: {

-               // Format momentjs object to the defined format for display

-               dateString: mTime.format(DATE_FORMAT),

-               timeString: mTime.format(TIME_FORMAT)

-             },

-             displayTimeEnd: {

-               dateString: mTimeEnd.format(DATE_FORMAT),

-               timeString: mTimeEnd.format(TIME_FORMAT),

-             },

+             time: mTime,

+             timeEnd: mTimeEnd,

              location: m.meeting_location,

            };

          }))

Closes #58

Known Issues:

  • This utilizes JS Intl API. This is horribly broken on Firefox from the repos, which completely disregards the system locale.
  • There is a disparity in the fedocal APIs. The meeting reminders that are sent in emails, the fedocal documentation and the events that are entered are completely out-of-sync! This leads to confusion in timezones Confirmed that FedoCal API gives out date and time in UTC (See below).

rebased onto a67b985d7408c12edabcb5bf3b698088fa9909e7

10 months ago

rebased onto 103b5228968311166c6c172b85890f7f3a9798e3

10 months ago

Confirmed API returns time in UTC

Here's the discussion @ #fedora-apps

[15:27] <amitosh> hi all! We are building the android app which interacts with fedocal API
[15:28] <amitosh> Can someone clarify about whether the time returned by /meeting endpoint is in UTC?
[15:29] <cverna> pingou: ^^
[15:30] <pingou> I believe it is
[15:30] <cverna> amitosh: I would say yes
[15:30] <pingou> but it should say so
[15:30] <pingou> amitosh: there is a meeting_timezone
[15:31] <pingou> that explicits the timezone
[15:37] <amitosh> pingou, cverna thanks for the response
[15:37] <amitosh> pingou: so meeting_timezone says the time zone for the meeting_time_start and meeting_time_stop?
[15:38] <pingou> yup
[15:38] <amitosh> We tried that, but we are getting incorrect results
[15:39] <amitosh> In case of fedora join sig (https://fedoraproject.org/wiki/SIGs/Join/Next_Meeting?rd=Fedora_Join_SIG/Next_Meeting)
[15:40] <amitosh> meeting_time_start: "17:00:00"
[15:40] <amitosh> meeting_time_stop: "18:00:00"
[15:40] <amitosh> meeting_timezone: "Europe/London"
[15:40] <amitosh> "Europe/London" !== "UTC", they have dst and other stuff :/
[15:40] <pingou> it could be that the wiki is outdated or that the person entering the entry in fedocal didn't set the right timezone
[15:41] <pingou> the usual error in, error out :)
[15:42] <amitosh> not just that, the same error is for all the meetings in QA!
[15:43] <pingou> https://apps.fedoraproject.org/calendar/meeting/9231/?from_date=2018-06-12
[15:43] <pingou>     Start: Tue, June 12, 2018 - 16:00 UTC
[15:44] <pingou>     End: Tue, June 12, 2018 - 17:00:00 UTC
[15:45] <pingou> this is odd indeed
[15:46] <pingou> Stored as:
[15:46] <pingou>     Start: 2018-05-15 - 18:00:00 Europe/London
[15:46] <pingou>     End: 2018-05-15 - 19:00:00 Europe/London
[15:46] <pingou> so it's consistent
[16:59] <amitosh> pingou: Yes
[16:59] <amitosh> But this one here: https://apps.fedoraproject.org/calendar/api/meetings?calendar=QA
[16:59] <amitosh> meeting time is 15:00:00, and the meeting actually happens in 15:00 UTC
[17:27] <pingou> amitosh: Stored as:
[17:27] <pingou>     Start: 2018-06-04 - 11:00:00 America/New_York
[17:27] <pingou>     End: 2018-06-04 - 12:00:00 America/New_York
[17:28] <pingou> seeing this, I think you're right the start/stop times are given in UTC in the API
[17:28] <pingou> I'd have to double-check the code though, this surprises me a bit
[17:52] <amitosh> https://github.com/fedora-infra/fedocal/blob/master/fedocal/api.py#L393
[17:54] <amitosh> pingou: https://github.com/fedora-infra/fedocal/blob/master/fedocal/fedocallib/__init__.py#L800
[17:55] <amitosh> Indeed it is converted into UTC
[17:55] <amitosh> It makes sense to document this
[17:55] <pingou> +1
[17:55] <amitosh> I'll probably make a PR for this soon
[17:56] <pingou> thank you for that
[17:56] <pingou> I've on my todo to cut a new release one of these days
[17:56] <pingou> so I may wait for your PR so it's included

rebased onto cdc091c0e771fd15d6e08d4f96e16d6a30201558

10 months ago

Remove console statement if not required

Just curious, why so many downgrades ?

2 new commits added

  • Parse date & time from FedoCal correctly
  • Locale aware date-time display
10 months ago

rebased onto 44d881b

10 months ago

Pull-Request has been merged by a2batic

10 months ago