Buscar categorias, pacotes e repositórios

Detalhes do pacotev2.3.0

calendar_time

Implementação do tempo de calendário do MomentJS, além de vários outros métodos auxiliares.

AndroidiOSWebmacOSWindowsLinux
Downloads em 30 dias
124
Curtidas
27
Pontos Pub
130

Instalar pacote

flutter pub add calendar_time

Visão geral do pacote

Orientação gerada a partir de informações públicas. Apenas para referência.

Um pacote Flutter/Dart que implementa a formatação de tempo calendário do MomentJS, oferecendo exibições intuitivas de tempo relativo como 'em 2 horas' ou 'há 2 dias'. Inclui métodos auxiliares adicionais para manipulação e formatação de datas, facilitando o trabalho com timestamps em aplicações voltadas para usuários. Projetado para uso multiplataforma, suporta Android, iOS, Web, macOS, Windows e Linux. O pacote simplifica a apresentação de diferenças de tempo em um formato legível por humanos, melhorando a experiência do usuário em aplicativos que exigem exibições dinâmicas de tempo.

Casos de uso

  • Exibindo carimbos de tempo relativos em aplicativos de chat
  • Mostrando idades de postagens ou atividades em feeds sociais
  • Formatar diferenças de tempo em notificações
  • Melhorando a experiência do usuário com rótulos de tempo legíveis
  • Simplificando a lógica de data em aplicativos de gerenciamento de tarefas

Principais recursos

  • Formatação de tempo do calendário do estilo MomentJS
  • Compatibilidade multiplataforma
  • Métodos auxiliares para operações de data
  • Expressões de tempo legíveis
  • Integração fácil por meio do comando pub add

Indicado para

  • Aplicativos que precisam de exibição de tempo relativo
  • Desenvolvedores familiarizados com o MomentJS
  • Projetos que exigem formatação de tempo consistente
  • aplicações com interface intensiva e atualizações em tempo real
  • Equipes que priorizam a produtividade do desenvolvedor

Considerações

  • Requer compreensão dos conceitos de tempo relativo
  • Pode ser necessário configurar localização para locais não ingleses
  • Limitado à formatação de horário — sem análise completa de data
  • Depende da classe DateTime central do Dart
  • Não adequado para aritmética de data complexa

README original

Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.

calendar_time

Implementation of MomentJS's calendarTime function and some other helpful utilities.

I expect this project will get replaced with another more ambitious project in the future, but this has come in very handy. Extensions and pull requests welcome.

Usage

toHuman

Converting a DateTime to a human readable string

import 'package:calendar_time/calendar_time.dart';

main(){
  CalendarTime(DateTime.now()).toHuman; //Today at {current time}
}

Example output:

  • Today at {current time}
  • Tomorrow at {time}
  • Yesterday at {time}
  • {day} at {time}
  • Last {day} at {time}
  • date time (outside of the last or upcoming few weeks)

Honestly just check the code, but it is in line with Moment's logic.

You can also call .toHumanMultiLine that splits the output around at to have date and time on different lines.

format

Formats to current timezone

import 'package:calendar_time/calendar_time.dart';

main(){
  CalendarTime(DateTime.now()).format("yyyy-MM-dd HH:mm");
}

See https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html for options.

isToday

Return if the supplied DateTime is today

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.isToday; //true
}
isTomorrow

Return if the supplied DateTime is tomorrow

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.isTomorrow; //false
}
isNextWeek

Return if the supplied DateTime is next week

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.isNextWeek; //false
}
isYesterday

Return if the supplied DateTime is yesterday

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.isYesterday; //false
}
isLastweek

Return if the supplied DateTime is last week

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.isLastWeek; //false
}
startOfToday

Return the beginning of today - not to be confused with startOfDay

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.startOfToday; // DateTime
}
startOfDay

Return the beginning of the day of the CalendarTime obejct.

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime(2020,1,1));
  calendarTime.startOfDay; // 2020/01/01 0:0:0am
}
startOfYesterday

Return the beginning of yesterday

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.startOfYesterday; // DateTime start of yesterday
}
startOfLastWeek

Return the beginning of lastWeek

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.startOfLastWeek; // DateTime start of yesterday
}
endOfToday

Return the end of today (23:59:59:999:999) - not to be confused with endOfDay

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.endOfToday; // DateTime
}
endOfDay

Return the end of the day of the CalendarTime object (23:59:59:999:999)

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime(2020, 1,1));
  calendarTime.endOfToday; // 2020/01/01 23:59:59:999:999
}
endOfTomorrow

Return the end of tomorrow

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.endOfTomorrow; // DateTime
}
endOfNextWeek

Return the end of next week

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.endOfNextWeek; // DateTime
}

Categorias

Dependências

Lista de dependências 1 itens

Repositório-fonte

Projetos que usam este pacote

Ainda não há dados.