@wilm-ai/wilma-client 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,8 +5,21 @@ export function parseWilmaTimestamp(value) {
5
5
  if (typeof value === "number") {
6
6
  return new Date(value * 1000);
7
7
  }
8
- const text = String(value)
9
- .trim()
8
+ const raw = String(value).trim();
9
+ // Try ISO 8601 format first (e.g., "2026-02-05T13:56:42.737Z")
10
+ if (/^\d{4}-\d{2}-\d{2}T/.test(raw)) {
11
+ const parsed = new Date(raw);
12
+ if (!isNaN(parsed.getTime())) {
13
+ return parsed;
14
+ }
15
+ }
16
+ // Try Unix timestamp as string
17
+ if (/^\d{10,13}$/.test(raw)) {
18
+ const num = Number(raw);
19
+ // 10 digits = seconds, 13 digits = milliseconds
20
+ return new Date(raw.length === 10 ? num * 1000 : num);
21
+ }
22
+ const text = raw
10
23
  .toLowerCase()
11
24
  .replace("klo", "")
12
25
  .replace("julkaistu", "")
@@ -23,8 +23,12 @@ export function parseExamsHtml(html) {
23
23
  return;
24
24
  }
25
25
  const [d, m, y] = match[1].split(".").map(Number);
26
- const examDate = new Date(y, m - 1, d);
27
- const subjDesc = $(firstCells.get(1)).text().trim();
26
+ // Use midday UTC to avoid timezone date shifts in JSON output
27
+ const examDate = new Date(Date.UTC(y, m - 1, d, 12, 0, 0));
28
+ // Also store as local date string to avoid any serialization issues
29
+ const dateString = `${y}-${String(m).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
30
+ // Compact whitespace first to normalize the text before parsing
31
+ const subjDesc = compactText($(firstCells.get(1)).text());
28
32
  let subject = subjDesc;
29
33
  let description = null;
30
34
  if (subjDesc.includes(":")) {
@@ -57,13 +61,17 @@ export function parseExamsHtml(html) {
57
61
  exams.push({
58
62
  wilmaId: autoId,
59
63
  examDate,
60
- subject: subject || "(N/A)",
61
- description,
62
- teacher,
63
- notes,
64
+ dateString,
65
+ subject: compactText(subject || "(N/A)"),
66
+ description: description ? compactText(description) : null,
67
+ teacher: teacher ? compactText(teacher) : null,
68
+ notes: notes ? compactText(notes) : null,
64
69
  fetchedAt: now,
65
70
  });
66
71
  autoId += 1;
67
72
  });
68
73
  return exams;
69
74
  }
75
+ function compactText(value) {
76
+ return value.replace(/\s+/g, " ").trim();
77
+ }
@@ -1,3 +1,5 @@
1
1
  import type { Message, MessageFolder } from "../types.js";
2
2
  export declare function parseMessagesList(data: unknown, folder: MessageFolder): Message[];
3
3
  export declare function parseMessageDetailHtml(html: string, messageId: number): Message;
4
+ /** Export for debugging - returns raw field names from first message */
5
+ export declare function debugMessageFields(data: unknown): string[];
@@ -6,8 +6,23 @@ export function parseMessagesList(data, folder) {
6
6
  return list.flatMap((item) => {
7
7
  try {
8
8
  const wilmaId = Number(item["id"] ?? item["Id"]);
9
- const subject = String(item["Subject"] ?? item["subject"] ?? "");
10
- const timeValue = item["Time"] ?? item["time"];
9
+ const subject = compactText(String(item["Subject"] ?? item["subject"] ?? ""));
10
+ // Try many possible field names for the timestamp
11
+ const timeValue = item["Time"] ??
12
+ item["time"] ??
13
+ item["TimeStamp"] ??
14
+ item["Timestamp"] ??
15
+ item["timestamp"] ??
16
+ item["SentAt"] ??
17
+ item["sentAt"] ??
18
+ item["Sent"] ??
19
+ item["sent"] ??
20
+ item["Date"] ??
21
+ item["date"] ??
22
+ item["Created"] ??
23
+ item["created"] ??
24
+ item["CreatedAt"] ??
25
+ item["createdAt"];
11
26
  return [
12
27
  {
13
28
  wilmaId,
@@ -112,3 +127,14 @@ function normalizeMessagesList(data) {
112
127
  }
113
128
  return [];
114
129
  }
130
+ /** Export for debugging - returns raw field names from first message */
131
+ export function debugMessageFields(data) {
132
+ const list = normalizeMessagesList(data);
133
+ if (list.length > 0) {
134
+ return Object.keys(list[0]);
135
+ }
136
+ return [];
137
+ }
138
+ function compactText(value) {
139
+ return value.replace(/\s+/g, " ").trim();
140
+ }
package/dist/types.d.ts CHANGED
@@ -24,6 +24,8 @@ export interface NewsItem {
24
24
  export interface Exam {
25
25
  wilmaId: number;
26
26
  examDate: Date;
27
+ /** Local date string in YYYY-MM-DD format (avoids timezone serialization issues) */
28
+ dateString: string;
27
29
  subject: string;
28
30
  description?: string | null;
29
31
  teacher?: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wilm-ai/wilma-client",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",