Skip to content

Instantly share code, notes, and snippets.

@psenger
Last active January 22, 2025 21:27
Show Gist options
  • Save psenger/e5573f9f2c4840cce110062355837d8a to your computer and use it in GitHub Desktop.
Save psenger/e5573f9f2c4840cce110062355837d8a to your computer and use it in GitHub Desktop.
[Date Format Australia aussie-dates] #JavaScript #Date

🦘 Aussie Dates πŸ‡¦πŸ‡Ί

G'day mate! Welcome to the most fair dinkum date formatting library this side of the Southern Hemisphere!

πŸ€” What's This All About?

Ever needed to format your dates in proper Australian style but got lost in the outback of date formatting? No worries! This little beauty's got you covered with all the date formats you'll ever need in the land down under.

🎯 Features

  • βœ… Standard Australian format (23/01/2025)
  • βœ… Casual format for your arvo catch-ups (3/1/2025)
  • βœ… Fancy format for your formal occasions (Thursday, 23 January 2025)
  • βœ… Short and sweet format (23 Jan 2025)
  • βœ… Tech-savvy ISO format (2025-01-23)

πŸ“¦ Installation

yeah, nah, just copy it from here.

πŸš€ Usage

if you fancy, call the file aussie-dates.js then....

const { formatAustralianDate } = require('aussie-dates');

const date = new Date(2025, 0, 23);
console.log(formatAustralianDate(date)); // Outputs: 23/01/2025

🎨 Available Formats

Here's what you can do with this ripper of a library:

const date = new Date(2025, 0, 23);

formatAustralianDate(date)     // -> "23/01/2025"
formatInformalDate(date)       // -> "23/1/2025"
formatShortReadableDate(date)  // -> "23 Jan 2025"
formatLongDate(date)           // -> "Thursday, 23 January 2025"
formatISODate(date)            // -> "2025-01-23"

🀝 Contributing

Found a bug? Got a suggestion? Don't be a galah - raise an issue or send us a pull request! We're friendly as, mate!

πŸ“ License

MIT License - Feel free to use it in your projects, no dramas!

πŸ¦… A Note on Time Zones

Remember mate, Australia's got more time zones than a kangaroo's got hops:

  • AEST (Australian Eastern Standard Time)
  • ACST (Australian Central Standard Time)
  • AWST (Australian Western Standard Time)

Plus we've got that daylight savings thing in some states (looking at you, Victoria)!

πŸŽ‰ Credits

Made with ❀️ by developers who know their dates from their dingoes!


Remember: Time's like a boomerang in Australia - it always comes back around! πŸͺƒ

/**
* @fileoverview 🦘 G'day! This module provides comprehensive date formatting utilities
* specifically for Australian date formats. Perfect for when you need your dates to
* speak Australian! πŸ‡¦πŸ‡Ί
*
* @module aussie-dates
* @author Your Name
* @version 1.0.0
*/
/**
* Common date format patterns in Australia:
* - dd/mm/yyyy (23/01/2025) - Most common numeric format
* - d/m/yyyy (3/1/2025) - Informal numeric format
* - dd-mm-yyyy (23-01-2025) - Alternative numeric format
* - dd mmm yyyy (23 Jan 2025) - Common readable format
* - dddd, d mmmm yyyy (Thursday, 23 January 2025) - Formal long format
* - yyyy-mm-dd (2025-01-23) - ISO format (used in technical contexts)
*/
/**
* Formats a date in the standard Australian numeric format (dd/mm/yyyy)
* @param {Date} date - The date to format
* @returns {string} The formatted date string
* @example
* // Returns "23/01/2025"
* formatAustralianDate(new Date(2025, 0, 23))
*/
const formatAustralianDate = (date) => {
const day = date.getDate().toString().padStart(2, '0');
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const year = date.getFullYear();
return `${day}/${month}/${year}`;
};
/**
* Formats a date in the informal Australian numeric format (d/m/yyyy)
* @param {Date} date - The date to format
* @returns {string} The formatted date string
* @example
* // Returns "3/1/2025"
* formatInformalDate(new Date(2025, 0, 3))
*/
const formatInformalDate = (date) => {
const day = date.getDate();
const month = date.getMonth() + 1;
const year = date.getFullYear();
return `${day}/${month}/${year}`;
};
/**
* Formats a date in the Australian short readable format (dd mmm yyyy)
* @param {Date} date - The date to format
* @returns {string} The formatted date string
* @example
* // Returns "23 Jan 2025"
* formatShortReadableDate(new Date(2025, 0, 23))
*/
const formatShortReadableDate = (date) => {
const day = date.getDate().toString().padStart(2, '0');
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const month = monthNames[date.getMonth()];
const year = date.getFullYear();
return `${day} ${month} ${year}`;
};
/**
* Formats a date in the formal Australian long format (dddd, d mmmm yyyy)
* @param {Date} date - The date to format
* @returns {string} The formatted date string
* @example
* // Returns "Thursday, 23 January 2025"
* formatLongDate(new Date(2025, 0, 23))
*/
const formatLongDate = (date) => {
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday'];
const monthNames = ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'];
const dayName = days[date.getDay()];
const day = date.getDate();
const month = monthNames[date.getMonth()];
const year = date.getFullYear();
return `${dayName}, ${day} ${month} ${year}`;
};
/**
* Formats a date in ISO format (yyyy-mm-dd), commonly used in technical contexts
* @param {Date} date - The date to format
* @returns {string} The formatted date string
* @example
* // Returns "2025-01-23"
* formatISODate(new Date(2025, 0, 23))
*/
const formatISODate = (date) => {
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
return `${year}-${month}-${day}`;
};
module.exports = {
formatAustralianDate,
formatInformalDate,
formatShortReadableDate,
formatLongDate,
formatISODate
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment